decompiled_code:
void __fastcall arg_put_name(char *a1)
{
__int64 v1; // rcx
__int64 v2; // rsi
__int64 v3; // rax

if ( (a1[80] & 2) != 0 || *((_QWORD *)a1 + 1) )
return;
v1 = *(unsigned int *)a1;
if ( (_DWORD)v1 == 1 )
{
if ( *((_QWORD *)a1 + 3) )
{
type_list_move((__int64)a1, (__int64 *)a1 + 3);
v3 = *((_QWORD *)a1 + 1);
goto LABEL_12;
}
LABEL_19:
bug("argument.c", 175LL, "attempt to move non-existent name from pointer list");
LABEL_20:
bug("argument.c", 185LL, "attempt to move a shared type to arg name");
arg_free();
return;
}
if ( (unsigned int)v1 <= 1 )
goto LABEL_9;
if ( (_DWORD)v1 == 2 )
{
LABEL_18:
bug("argument.c", 194LL, "attempt to move a suffix to arg name");
goto LABEL_19;
}
if ( (_DWORD)v1 != 3 )
{
bug("argument.c", 197LL, "a->parse_state had bad value %d", v1);
goto LABEL_18;
}
while ( 1 )
{
a1 = "argument.c";
bug("argument.c", 201LL, "Could not find a name");
LABEL_9:
v2 = *((_QWORD *)a1 + 2);
if ( !*(_QWORD *)v2 )
break;
if ( *(int *)(v2 + 8) > 1 )
goto LABEL_20;
type_list_move((__int64)a1, (__int64 *)v2);
v3 = *((_QWORD *)a1 + 1);
LABEL_12:
if ( v3 )
{
*(_DWORD *)a1 = 2;
return;
}
}
}

canonical_decompiled_code:
void __fastcall func10(char *a1)
{
__int64 v1; // rcx
__int64 v2; // rsi
__int64 v3; // rax

if ( (a1[80] & 2) != 0 || *((_QWORD *)a1 + 1) )
return;
v1 = *(unsigned int *)a1;
if ( (_DWORD)v1 == 1 )
{
if ( *((_QWORD *)a1 + 3) )
{
func1((__int64)a1, (__int64 *)a1 + 3);
v3 = *((_QWORD *)a1 + 1);
goto LABEL_12;
}
LABEL_19:
bug("argument.c", 175LL, "attempt to move non-existent name from pointer list");
LABEL_20:
bug("argument.c", 185LL, "attempt to move a shared type to arg name");
func11();
return;
}
if ( (unsigned int)v1 <= 1 )
goto LABEL_9;
if ( (_DWORD)v1 == 2 )
{
LABEL_18:
bug("argument.c", 194LL, "attempt to move a suffix to arg name");
goto LABEL_19;
}
if ( (_DWORD)v1 != 3 )
{
bug("argument.c", 197LL, "a->parse_state had bad value %d", v1);
goto LABEL_18;
}
while ( 1 )
{
a1 = "argument.c";
bug("argument.c", 201LL, "Could not find a name");
LABEL_9:
v2 = *((_QWORD *)a1 + 2);
if ( !*(_QWORD *)v2 )
break;
if ( *(int *)(v2 + 8) > 1 )
goto LABEL_20;
func1((__int64)a1, (__int64 *)v2);
v3 = *((_QWORD *)a1 + 1);
LABEL_12:
if ( v3 )
{
*(_DWORD *)a1 = 2;
return;
}
}
}

original_code:
void
arg_put_name (struct arg * a)
{
    if (a->is_function_pointer) {
        return;
    }
    if (a->name) {
        return;
    }
    switch (a->parse_state) {
    case POINTER:
 if (! a->pointers) {
     bug ("argument.c", 175, "attempt to move non-existent name from pointer list");
 }
 type_list_move (a, & a->pointers);
 break;
    case TYPE:
 if (! a->types->t) {
     return;
 }
 if (a->types->ref_count > 1) {
     bug ("argument.c", 185, "attempt to move a shared type to arg name");
 }
 type_list_move (a, & a->types->t);
 break;
    case CPP_MUDDLE:
 break;
    case SUFFIX:
 bug ("argument.c", 194, "attempt to move a suffix to arg name");
    default:
        bug ("argument.c", 197, "a->parse_state had bad value %d", a->parse_state);
    }
    if (! a->name) {
 bug ("argument.c", 201, "Could not find a name");
    }
    a->parse_state = SUFFIX;
}

canonical_original_code:
void arg_put_name(struct arg *a)
{
    if (a->is_function_pointer) {
        return;
    }
    if (a->name) {
        return;
    }
    switch (a->parse_state) {
    case POINTER:
 if (! a->pointers) {
     bug ("argument.c", 175, "attempt to move non-existent name from pointer list");
 }
 type_list_move (a, & a->pointers);
 break;
    case TYPE:
 if (! a->types->t) {
     return;
 }
 if (a->types->ref_count > 1) {
     bug ("argument.c", 185, "attempt to move a shared type to arg name");
 }
 type_list_move (a, & a->types->t);
 break;
    case CPP_MUDDLE:
 break;
    case SUFFIX:
 bug ("argument.c", 194, "attempt to move a suffix to arg name");
    default:
        bug ("argument.c", 197, "a->parse_state had bad value %d", a->parse_state);
    }
    if (! a->name) {
 bug ("argument.c", 201, "Could not find a name");
    }
    a->parse_state = SUFFIX;
}


repo: benkasminbullock/cfunctions

original_code:
void
arg_free (struct arg * a)
{
    a->types->ref_count--;
    if (a->types->ref_count == 0) {
 type_free (a->types->t);
 free_or_exit (a->types);
 a->types = 0;
 arg_n_mallocs--;
    }
    if (a->name) {
 free_or_exit (a->name->name);
 a->name->name = 0;
 arg_n_mallocs--;
 free_or_exit (a->name);
 a->name = 0;
 arg_n_mallocs--;
    }
    type_free (a->pointers);
    type_free (a->suffixes);
    if (a->prev) {
 arg_free (a->prev);
    }
    if (a->is_function_pointer) {
 if (a->function_pointer) {
     free_or_exit (a->function_pointer);
     a->function_pointer = 0;
 }
    }
    if (a->function_pointer_arguments) {
 free_or_exit (a->function_pointer_arguments);
 a->function_pointer_arguments = 0;
    }
    free_or_exit (a);
    a = 0;
    arg_n_mallocs--;
}

canonical_original_code:
void arg_free(struct arg *a)
{
    a->types->ref_count--;
    if (a->types->ref_count == 0) {
 type_free (a->types->t);
 free_or_exit (a->types);
 a->types = 0;
 arg_n_mallocs--;
    }
    if (a->name) {
 free_or_exit (a->name->name);
 a->name->name = 0;
 arg_n_mallocs--;
 free_or_exit (a->name);
 a->name = 0;
 arg_n_mallocs--;
    }
    type_free (a->pointers);
    type_free (a->suffixes);
    if (a->prev) {
 arg_free (a->prev);
    }
    if (a->is_function_pointer) {
 if (a->function_pointer) {
     free_or_exit (a->function_pointer);
     a->function_pointer = 0;
 }
    }
    if (a->function_pointer_arguments) {
 free_or_exit (a->function_pointer_arguments);
 a->function_pointer_arguments = 0;
    }
    free_or_exit (a);
    a = 0;
    arg_n_mallocs--;
}

variable_types: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type { unsigned char *name; struct type *next; struct type *prev; } *name; struct shared_type { struct type *t; int ref_count; } *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; } *

return_type: void

user_defined_types: struct arg { enum { TYPE=0, POINTER=1, SUFFIX=2, CPP_MUDDLE=3 } parse_state; struct type *name; struct shared_type *types; struct type *pointers; struct type *suffixes; unsigned int line; struct arg *prev; struct arg *next; char *function_pointer; char *function_pointer_arguments; unsigned int is_typedef; unsigned int is_function_pointer; }


decompiled_code:
int arg_memory_check()
{
int result; // eax

if ( arg_n_mallocs )
result = fprintf(stderr, "%s:%d: arg_n_mallocs = %d\n", "argument.c", 402LL, (unsigned int)arg_n_mallocs);
return result;
}

canonical_decompiled_code:
int func14()
{
int result; // eax

if ( arg_n_mallocs )
result = fprintf(stderr, "%s:%d: arg_n_mallocs = %d\n", "argument.c", 402LL, (unsigned int)arg_n_mallocs);
return result;
}

original_code:
void
arg_memory_check ()
{
    if (arg_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: arg_n_mallocs = %d\n",
   "argument.c", 402, arg_n_mallocs);
    }
}

canonical_original_code:
void arg_memory_check()
{
    if (arg_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: arg_n_mallocs = %d\n",
   "argument.c", 402, arg_n_mallocs);
    }
}


fexists

decompiled_code:
__int64 __fastcall fexists(const char *errnum)
{
int v1; // ebp
int v2; // edi
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

v1 = (int)errnum;
if ( !stat(errnum, &v5) )
return 1LL;
v2 = *_errno_location();
if ( v2 == 2 )
return 0LL;
v4 = strerror(v2);
error((int)"could not stat %s: %s", v1, v4);
return file_memory_check();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *errnum)
{
int v1; // ebp
int v2; // edi
char *v4; // rax
struct stat v5; // [rsp+0h] [rbp-98h] BYREF

v1 = (int)errnum;
if ( !stat(errnum, &v5) )
return 1LL;
v2 = *_errno_location();
if ( v2 == 2 )
return 0LL;
v4 = strerror(v2);
error((int)"could not stat %s: %s", v1, v4);
return func3();
}

original_code:
int
fexists (const char * file_name)
{
    struct stat dummy;
    if (stat (file_name, & dummy)) {
 if ((*__errno_location ()) != 2) {
     error ("could not stat %s: %s", file_name, strerror ((*__errno_location ())));
 }
 return 0;
    }
    return 1;
}

canonical_original_code:
int fexists(char *file_name)
{
    struct stat dummy;
    if (stat (file_name, & dummy)) {
 if ((*__errno_location ()) != 2) {
     error ("could not stat %s: %s", file_name, strerror ((*__errno_location ())));
 }
 return 0;
    }
    return 1;
}

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

return_type: int

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


decompiled_code:
int file_memory_check()
{
int result; // eax

if ( file_n_mallocs )
result = fprintf(stderr, "%s:%d: file_n_mallocs = %d.\n", "file.c", 161LL, (unsigned int)file_n_mallocs);
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

if ( file_n_mallocs )
result = fprintf(stderr, "%s:%d: file_n_mallocs = %d.\n", "file.c", 161LL, (unsigned int)file_n_mallocs);
return result;
}

original_code:
void
file_memory_check ()
{
    if (file_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: file_n_mallocs = %d.\n",
   "file.c", 161, file_n_mallocs);
    }
}

canonical_original_code:
void file_memory_check()
{
    if (file_n_mallocs != 0) {
 fprintf (stderr, "%s:%d: file_n_mallocs = %d.\n",
   "file.c", 161, file_n_mallocs);
    }
}


decompiled_code:
int xbee_init()
{
__int64 v0; // rax

LODWORD(v0) = pthread_key_create(&threadInfoKey, 0LL);
if ( !xbeeList )
{
v0 = xbee_ll_alloc();
xbeeList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize xbeeList...\n", 1uLL, 0x2AuLL, stderr);
}
if ( !conList )
{
v0 = xbee_ll_alloc();
conList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize conList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !pktList )
{
v0 = xbee_ll_alloc();
pktList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize pktList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !netDeadClientList )
{
v0 = xbee_ll_alloc();
netDeadClientList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize netDeadClientList...\n", 1uLL, 0x33uLL, stderr);
}
if ( !threadList )
{
v0 = xbee_ll_alloc();
threadList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize threadList...\n", 1uLL, 0x2CuLL, stderr);
}
if ( !needsFree )
{
v0 = xbee_ll_alloc();
needsFree = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize needsFree...\n", 1uLL, 0x2BuLL, stderr);
}
return v0;
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rax

LODWORD(v0) = pthread_key_create(&threadInfoKey, 0LL);
if ( !xbeeList )
{
v0 = xbee_ll_alloc();
xbeeList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize xbeeList...\n", 1uLL, 0x2AuLL, stderr);
}
if ( !conList )
{
v0 = xbee_ll_alloc();
conList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize conList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !pktList )
{
v0 = xbee_ll_alloc();
pktList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize pktList...\n", 1uLL, 0x29uLL, stderr);
}
if ( !netDeadClientList )
{
v0 = xbee_ll_alloc();
netDeadClientList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize netDeadClientList...\n", 1uLL, 0x33uLL, stderr);
}
if ( !threadList )
{
v0 = xbee_ll_alloc();
threadList = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize threadList...\n", 1uLL, 0x2CuLL, stderr);
}
if ( !needsFree )
{
v0 = xbee_ll_alloc();
needsFree = v0;
if ( !v0 )
LODWORD(v0) = fwrite("libxbee: failed to initialize needsFree...\n", 1uLL, 0x2BuLL, stderr);
}
return v0;
}

original_code:
__attribute__((visibility("default"))) __attribute__((constructor)) void xbee_init(void) {
 pthread_key_create((&threadInfoKey), (((void *)0)));
 if (!xbeeList && (xbeeList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize xbeeList...\n");
 }
 if (!conList && (conList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize conList...\n");
 }
 if (!pktList && (pktList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize pktList...\n");
 }
 if (!netDeadClientList && (netDeadClientList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize netDeadClientList...\n");
 }
 if (!threadList && (threadList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize threadList...\n");
 }
 if (!needsFree && (needsFree = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize needsFree...\n");
 }
}

canonical_original_code:
void xbee_init() {
 pthread_key_create((&threadInfoKey), (((void *)0)));
 if (!xbeeList && (xbeeList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize xbeeList...\n");
 }
 if (!conList && (conList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize conList...\n");
 }
 if (!pktList && (pktList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize pktList...\n");
 }
 if (!netDeadClientList && (netDeadClientList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize netDeadClientList...\n");
 }
 if (!threadList && (threadList = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize threadList...\n");
 }
 if (!needsFree && (needsFree = xbee_ll_alloc()) == ((void *)0)) {
  fprintf(stderr, "libxbee: failed to initialize needsFree...\n");
 }
}


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

if ( threadList )
{
result = xbee_ll_free(threadList, &xbee_threadKillThis);
threadList = 0LL;
}
if ( xbeeList )
{
result = xbee_ll_free(xbeeList, &xbee_shutdown);
xbeeList = 0LL;
}
if ( conList )
{
result = xbee_ll_free(conList, &xbee_conEnd);
conList = 0LL;
}
if ( pktList )
{
result = xbee_ll_free(pktList, &xbee_pktFree);
pktList = 0LL;
}
if ( netDeadClientList )
{
result = xbee_ll_free(netDeadClientList, &xbee_netClientShutdown);
netDeadClientList = 0LL;
}
if ( needsFree )
{
result = xbee_ll_free(needsFree, &free);
needsFree = 0LL;
}
return result;
}

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

if ( threadList )
{
result = xbee_ll_free(threadList, &xbee_threadKillThis);
threadList = 0LL;
}
if ( xbeeList )
{
result = xbee_ll_free(xbeeList, &xbee_shutdown);
xbeeList = 0LL;
}
if ( conList )
{
result = xbee_ll_free(conList, &xbee_conEnd);
conList = 0LL;
}
if ( pktList )
{
result = xbee_ll_free(pktList, &xbee_pktFree);
pktList = 0LL;
}
if ( netDeadClientList )
{
result = xbee_ll_free(netDeadClientList, &xbee_netClientShutdown);
netDeadClientList = 0LL;
}
if ( needsFree )
{
result = xbee_ll_free(needsFree, &free);
needsFree = 0LL;
}
return result;
}

original_code:
__attribute__((visibility("default"))) __attribute__((destructor)) void xbee_fini(void) {
 if (threadList) {
  xbee_ll_free(threadList, (void(*)(void*))xbee_threadKillThis);
  threadList = ((void *)0);
 }
 if (xbeeList) {
  xbee_ll_free(xbeeList, (void(*)(void*))xbee_shutdown);
  xbeeList = ((void *)0);
 }
 if (conList) {
  xbee_ll_free(conList, (void(*)(void*))xbee_conEnd);
  conList = ((void *)0);
 }
 if (pktList) {
  xbee_ll_free(pktList, (void(*)(void*))xbee_pktFree);
  pktList = ((void *)0);
 }
 if (netDeadClientList) {
  xbee_ll_free(netDeadClientList, (void(*)(void*))xbee_netClientShutdown);
  netDeadClientList = ((void *)0);
 }
 if (needsFree) {
  xbee_ll_free(needsFree, (void(*)(void*))free);
  needsFree = ((void *)0);
 }
}

canonical_original_code:
void xbee_fini() {
 if (threadList) {
  xbee_ll_free(threadList, (void (*)(void *))xbee_threadKillThis);
  threadList = ((void *)0);
 }
 if (xbeeList) {
  xbee_ll_free(xbeeList, (void (*)(void *))xbee_shutdown);
  xbeeList = ((void *)0);
 }
 if (conList) {
  xbee_ll_free(conList, (void (*)(void *))xbee_conEnd);
  conList = ((void *)0);
 }
 if (pktList) {
  xbee_ll_free(pktList, (void (*)(void *))xbee_pktFree);
  pktList = ((void *)0);
 }
 if (netDeadClientList) {
  xbee_ll_free(netDeadClientList, (void (*)(void *))xbee_netClientShutdown);
  netDeadClientList = ((void *)0);
 }
 if (needsFree) {
  xbee_ll_free(needsFree, (void (*)(void *))free);
  needsFree = ((void *)0);
 }
}


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

result = 0LL;
if ( gFd < 0 )
{
gFd = open("/dev/user-gpio", 2);
result = (unsigned int)(gFd >> 31);
}
return result;
}

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

result = 0LL;
if ( gFd < 0 )
{
gFd = open("/dev/user-gpio", 2);
result = (unsigned int)(gFd >> 31);
}
return result;
}

original_code:
int gpio_init( void )
{
    if ( gFd < 0 )
    {
        if (( gFd = open( "/dev/user-gpio", 02 )) < 0 )
        {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int gpio_init()
{
    if ( gFd < 0 )
    {
        if (( gFd = open( "/dev/user-gpio", 02 )) < 0 )
        {
            return -1;
        }
    }
    return 0;
}


decompiled_code:
int gpio_term()
{
int result; // eax

if ( gFd >= 0 )
{
result = close(gFd);
gFd = -1;
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

if ( gFd >= 0 )
{
result = close(gFd);
gFd = -1;
}
return result;
}

original_code:
void gpio_term( void )
{
    if ( gFd >= 0 )
    {
        close( gFd );
        gFd = -1;
    }
}

canonical_original_code:
void gpio_term()
{
    if ( gFd >= 0 )
    {
        close( gFd );
        gFd = -1;
    }
}


decompiled_code:
int __fastcall gpio_request(int a1, const char *a2)
{
int result; // eax
int v3; // [rsp+0h] [rbp-38h] BYREF
char dest[52]; // [rsp+4h] [rbp-34h] BYREF

v3 = a1;
strncpy(dest, a2, 0x1FuLL);
dest[31] = 0;
result = ioctl(gFd, 0x40244780uLL, &v3);
if ( result )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, const char *a2)
{
int result; // eax
int v3; // [rsp+0h] [rbp-38h] BYREF
char dest[52]; // [rsp+4h] [rbp-34h] BYREF

v3 = a1;
strncpy(dest, a2, 0x1FuLL);
dest[31] = 0;
result = ioctl(gFd, 0x40244780uLL, &v3);
if ( result )
result = -*_errno_location();
return result;
}

original_code:
int gpio_request( unsigned gpio, const char *label )
{
    GPIO_Request_t request;
    request.gpio = gpio;
    strncpy( request.label, label, sizeof( request.label ));
    request.label[ sizeof( request.label ) - 1 ] = '\0';
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x80)) << 0) | ((((sizeof(GPIO_Request_t)))) << ((0 +8)+8))), &request ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

canonical_original_code:
int gpio_request(unsigned int gpio, char *label)
{
    struct GPIO_Request_t request;
    request.gpio = gpio;
    strncpy( request.label, label, sizeof( request.label ));
    request.label[ sizeof( request.label ) - 1 ] = '\0';
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x80)) << 0) | ((((sizeof(GPIO_Request_t)))) << ((0 +8)+8))), &request ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

variable_types:
gpio
unsigned int

variable_types:
label
char *

variable_types: struct GPIO_Request_t { unsigned int gpio; char label[32]; }


decompiled_code:
int __fastcall gpio_free(unsigned int a1)
{
return ioctl(gFd, 0x4781uLL, a1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
return ioctl(gFd, 0x4781uLL, a1);
}


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

result = ioctl(gFd, 0x4782uLL, a1);
if ( result )
result = -*_errno_location();
return result;
}

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

result = ioctl(gFd, 0x4782uLL, a1);
if ( result )
result = -*_errno_location();
return result;
}


decompiled_code:
int __fastcall gpio_direction_output(int a1, int a2)
{
int result; // eax
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v3[1] = a2;
result = ioctl(gFd, 0x40084783uLL, v3);
if ( result )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, int a2)
{
int result; // eax
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v3[1] = a2;
result = ioctl(gFd, 0x40084783uLL, v3);
if ( result )
result = -*_errno_location();
return result;
}

original_code:
int gpio_direction_output( unsigned gpio, int initialValue )
{
    GPIO_Value_t setDirOutput;
    setDirOutput.gpio = gpio;
    setDirOutput.value = initialValue;
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x83)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setDirOutput ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

canonical_original_code:
int gpio_direction_output(unsigned int gpio, int initialValue)
{
    struct GPIO_Value_t setDirOutput;
    setDirOutput.gpio = gpio;
    setDirOutput.value = initialValue;
    if ( ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x83)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setDirOutput ) != 0 )
    {
        return -(*__errno_location ());
    }
    return 0;
}

variable_types: initialValue int

variable_types: struct GPIO_Value_t { unsigned int gpio; int value; }


decompiled_code:
__int64 __fastcall gpio_get_value(int a1)
{
int v1; // er8
__int64 result; // rax
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v1 = ioctl(gFd, 0xC0084784uLL, v3);
result = (unsigned int)v3[1];
if ( v1 )
result = (unsigned int)-*_errno_location();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // er8
__int64 result; // rax
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v1 = ioctl(gFd, 0xC0084784uLL, v3);
result = (unsigned int)v3[1];
if ( v1 )
result = (unsigned int)-*_errno_location();
return result;
}

original_code:
int gpio_get_value( unsigned gpio )
{
    GPIO_Value_t getValue;
    getValue.gpio = gpio;
    if ( ioctl( gFd, (((2U|1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x84)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &getValue ) != 0 )
    {
        return -(*__errno_location ());
    }
    return getValue.value;
}

canonical_original_code:
int gpio_get_value(unsigned int gpio)
{
    struct GPIO_Value_t getValue;
    getValue.gpio = gpio;
    if ( ioctl( gFd, (((2U|1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x84)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &getValue ) != 0 )
    {
        return -(*__errno_location ());
    }
    return getValue.value;
}

user_defined_types: struct GPIO_Value_t { unsigned int gpio; int value; }


decompiled_code:
int __fastcall gpio_set_value(int a1, int a2)
{
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v3[1] = a2;
return ioctl(gFd, 0x40084785uLL, v3);
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2)
{
int v3[4]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = a1;
v3[1] = a2;
return ioctl(gFd, 0x40084785uLL, v3);
}

original_code:
void gpio_set_value( unsigned gpio, int value )
{
    GPIO_Value_t setValue;
    setValue.gpio = gpio;
    setValue.value = value;
    ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x85)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setValue );
}

canonical_original_code:
void gpio_set_value(unsigned int gpio, int value)
{
    struct GPIO_Value_t setValue;
    setValue.gpio = gpio;
    setValue.value = value;
    ioctl( gFd, (((1U) << (((0 +8)+8)+14)) | ((('G')) << (0 +8)) | (((0x85)) << 0) | ((((sizeof(GPIO_Value_t)))) << ((0 +8)+8))), &setValue );
}

variable_types: value int


decompiled_code:
__int64 __fastcall xbee_modeGetList(_QWORD *a1)
{
int v1; // er15
void **v3; // r12
void **v4; // r14
__int64 v5; // rbp
const char **v6; // rbx
const char *v7; // rdi
const char **v8; // rax
char *v9; // rax
char *v10; // rbp
int v11; // er14
const char **v12; // rbx
char *v13; // rdi
const char **v14; // rax
__int64 v15; // rcx
__int64 result; // rax

if ( !a1 )
return 4294967284LL;
v1 = 0;
v3 = &modeList;
v4 = &modeList;
v5 = 0LL;
v6 = (const char **)&mode_xbee2;
v7 = (const char *)mode_xbee1;
if ( !mode_xbee1 )
goto LABEL_4;
while ( 1 )
{
++v1;
v5 += strlen(v7) + 9;
LABEL_4:
++v4;
if ( !v6 )
break;
while ( 1 )
{
v8 = v6;
v6 = (const char **)v4[1];
v7 = *v8;
if ( *v8 )
break;
++v4;
if ( !v6 )
goto LABEL_7;
}
}
LABEL_7:
v9 = (char *)malloc(v5 + 8);
v10 = v9;
if ( !v9 )
return 4294967294LL;
v11 = 0;
v12 = (const char **)&mode_xbee2;
v13 = &v9[8 * v1 + 8];
v14 = (const char **)&mode_xbee1;
if ( !mode_xbee1 )
goto LABEL_10;
while ( 1 )
{
v15 = v11++;
*(_QWORD *)&v10[8 * v15] = v13;
v13 = stpcpy(v13, *v14) + 1;
LABEL_10:
++v3;
if ( !v12 )
break;
while ( 1 )
{
v14 = v12;
v12 = (const char **)v3[1];
if ( *v14 )
break;
++v3;
if ( !v12 )
goto LABEL_13;
}
}
LABEL_13:
*a1 = v10;
result = 0LL;
*(_QWORD *)&v10[8 * v11] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
int v1; // er15
void **v3; // r12
void **v4; // r14
__int64 v5; // rbp
const char **v6; // rbx
const char *v7; // rdi
const char **v8; // rax
char *v9; // rax
char *v10; // rbp
int v11; // er14
const char **v12; // rbx
char *v13; // rdi
const char **v14; // rax
__int64 v15; // rcx
__int64 result; // rax

if ( !a1 )
return 4294967284LL;
v1 = 0;
v3 = &modeList;
v4 = &modeList;
v5 = 0LL;
v6 = (const char **)&mode_xbee2;
v7 = (const char *)mode_xbee1;
if ( !mode_xbee1 )
goto LABEL_4;
while ( 1 )
{
++v1;
v5 += strlen(v7) + 9;
LABEL_4:
++v4;
if ( !v6 )
break;
while ( 1 )
{
v8 = v6;
v6 = (const char **)v4[1];
v7 = *v8;
if ( *v8 )
break;
++v4;
if ( !v6 )
goto LABEL_7;
}
}
LABEL_7:
v9 = (char *)malloc(v5 + 8);
v10 = v9;
if ( !v9 )
return 4294967294LL;
v11 = 0;
v12 = (const char **)&mode_xbee2;
v13 = &v9[8 * v1 + 8];
v14 = (const char **)&mode_xbee1;
if ( !mode_xbee1 )
goto LABEL_10;
while ( 1 )
{
v15 = v11++;
*(_QWORD *)&v10[8 * v15] = v13;
v13 = stpcpy(v13, *v14) + 1;
LABEL_10:
++v3;
if ( !v12 )
break;
while ( 1 )
{
v14 = v12;
v12 = (const char **)v3[1];
if ( *v14 )
break;
++v3;
if ( !v12 )
goto LABEL_13;
}
}
LABEL_13:
*a1 = v10;
result = 0LL;
*(_QWORD *)&v10[8 * v11] = 0LL;
return result;
}

original_code:
__attribute__((visibility("default"))) xbee_err xbee_modeGetList(char ***retList) {
 int i, o;
 size_t memSize;
 char **mList;
 char *mName;
 if (!retList) return XBEE_EMISSINGPARAM;
 memSize = 0;
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  memSize += sizeof(char *);
  memSize += sizeof(char) * (strlen(modeList[i]->name) + 1);
  o++;
 }
 memSize += sizeof(char *);
 if ((mList = malloc(memSize)) == ((void *)0)) {
  return XBEE_ENOMEM;
 }
 mName = (char *)&(mList[o+1]);
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  mList[o] = mName;
  strcpy(mName, modeList[i]->name);
  mName += strlen(mName) + 1;
  o++;
 }
 mList[o] = ((void *)0);
 *retList = mList;
 return XBEE_ENONE;
}

canonical_original_code:
enum xbee_errors xbee_modeGetList(char ***retList) {
 int i; int o;
 unsigned long memSize;
 char **mList;
 char *mName;
 if (!retList) return XBEE_EMISSINGPARAM;
 memSize = 0;
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  memSize += sizeof(char *);
  memSize += sizeof(char) * (strlen(modeList[i]->name) + 1);
  o++;
 }
 memSize += sizeof(char *);
 if ((mList = malloc(memSize)) == ((void *)0)) {
  return XBEE_ENOMEM;
 }
 mName = (char *)&(mList[o+1]);
 for (i = 0, o = 0; modeList[i]; i++) {
  if (!modeList[i]->name) continue;
  mList[o] = mName;
  strcpy(mName, modeList[i]->name);
  mName += strlen(mName) + 1;
  o++;
 }
 mList[o] = ((void *)0);
 *retList = mList;
 return XBEE_ENONE;
}

variable_types:
retList
char ***

variable_types: i int

variable_types: o int

variable_types:
memSize
unsigned long

variable_types:
mList
char **

variable_types:
mName
char *

return_type: enum xbee_errors { XBEE_ENONE=0, XBEE_EUNKNOWN=-1, XBEE_ENOMEM=-2, XBEE_ESELECT=-3, XBEE_ESELECTINTERRUPTED=-4, XBEE_EEOF=-5, XBEE_EIO=-6, XBEE_ESEMAPHORE=-7, XBEE_EMUTEX=-8, XBEE_ETHREAD=-9, XBEE_ELINKEDLIST=-10, XBEE_ESETUP=-11, XBEE_EMISSINGPARAM=-12, XBEE_EINVAL=-13, XBEE_ERANGE=-14, XBEE_ELENGTH=-15, XBEE_EFAILED=-18, XBEE_ETIMEOUT=-17, XBEE_EWOULDBLOCK=-16, XBEE_EINUSE=-19, XBEE_EEXISTS=-20, XBEE_ENOTEXISTS=-21, XBEE_ENOFREEFRAMEID=-22, XBEE_ESTALE=-23, XBEE_ENOTIMPLEMENTED=-24, XBEE_ETX=-25, XBEE_EREMOTE=-26, XBEE_ESLEEPING=-27, XBEE_ECATCHALL=-28 }


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

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

original_code:
__attribute__((visibility("default"))) void xbee_freeMemory(void *ptr) {
 free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
const char *__fastcall xbee_errorToStr(int a1)
{
const char *result; // rax

switch ( a1 )
{
case -28:
result = "The given connection is a catch-all connection";
break;
case -27:
result = "The given connection is not currently awake";
break;
case -26:
result = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
break;
case -25:
result = "Transmission failed (check the retVal)";
break;
case -24:
result = "The called functionality has not yet been implemented";
break;
case -23:
result = "Stale information was used during this function call";
break;
case -22:
result = "There is currently no free frame ID that can be used for the request";
break;
case -21:
result = "The requested item does not exist";
break;
case -20:
result = "An item already exists by that name or identifier";
break;
case -19:
result = "A the item request is currently in use";
break;
case -18:
result = "A function call failed";
break;
case -17:
result = "A timeout occured";
break;
case -16:
result = "The call would block, but something is marked 'non-blocking'";
break;
case -15:
result = "A length mis-match occured";
break;
case -14:
result = "Requested data falls outside the boundaries";
break;
case -13:
result = "An invalid argument was provided";
break;
case -12:
result = "A crucial parameter was missing";
break;
case -11:
result = "Setup failed";
break;
case -10:
result = "A linkedlist error occured";
break;
case -9:
result = "A pthread error occured";
break;
case -8:
result = "A mutex error occured";
break;
case -7:
result = "A semaphore error occured";
break;
case -6:
result = "An I/O request failed";
break;
case -5:
result = "An EOF character was read";
break;
case -4:
result = "select() was interrupted";
break;
case -3:
result = "select() failed";
break;
case -2:
result = "Out of memory";
break;
case 0:
result = "No error";
break;
default:
result = "Unknown error...";
break;
}
return result;
}

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

switch ( a1 )
{
case -28:
result = "The given connection is a catch-all connection";
break;
case -27:
result = "The given connection is not currently awake";
break;
case -26:
result = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
break;
case -25:
result = "Transmission failed (check the retVal)";
break;
case -24:
result = "The called functionality has not yet been implemented";
break;
case -23:
result = "Stale information was used during this function call";
break;
case -22:
result = "There is currently no free frame ID that can be used for the request";
break;
case -21:
result = "The requested item does not exist";
break;
case -20:
result = "An item already exists by that name or identifier";
break;
case -19:
result = "A the item request is currently in use";
break;
case -18:
result = "A function call failed";
break;
case -17:
result = "A timeout occured";
break;
case -16:
result = "The call would block, but something is marked 'non-blocking'";
break;
case -15:
result = "A length mis-match occured";
break;
case -14:
result = "Requested data falls outside the boundaries";
break;
case -13:
result = "An invalid argument was provided";
break;
case -12:
result = "A crucial parameter was missing";
break;
case -11:
result = "Setup failed";
break;
case -10:
result = "A linkedlist error occured";
break;
case -9:
result = "A pthread error occured";
break;
case -8:
result = "A mutex error occured";
break;
case -7:
result = "A semaphore error occured";
break;
case -6:
result = "An I/O request failed";
break;
case -5:
result = "An EOF character was read";
break;
case -4:
result = "select() was interrupted";
break;
case -3:
result = "select() failed";
break;
case -2:
result = "Out of memory";
break;
case 0:
result = "No error";
break;
default:
result = "Unknown error...";
break;
}
return result;
}

original_code:
__attribute__((visibility("default"))) const char *xbee_errorToStr(xbee_err error) {
 char *str = "Unknown error...";
 switch (error) {
  case XBEE_ENONE:
   str = "No error";
   break;
  case XBEE_EUNKNOWN:
  default:
   str = "Unknown error...";
   break;
  case XBEE_ENOMEM:
   str = "Out of memory";
   break;
  case XBEE_ESELECT:
   str = "select() failed";
   break;
  case XBEE_ESELECTINTERRUPTED:
   str = "select() was interrupted";
   break;
  case XBEE_EEOF:
   str = "An EOF character was read";
   break;
  case XBEE_EIO:
   str = "An I/O request failed";
   break;
  case XBEE_ESEMAPHORE:
   str = "A semaphore error occured";
   break;
  case XBEE_EMUTEX:
   str = "A mutex error occured";
   break;
  case XBEE_ETHREAD:
   str = "A pthread error occured";
   break;
  case XBEE_ELINKEDLIST:
   str = "A linkedlist error occured";
   break;
  case XBEE_ESETUP:
   str = "Setup failed";
   break;
  case XBEE_EMISSINGPARAM:
   str = "A crucial parameter was missing";
   break;
  case XBEE_EINVAL:
   str = "An invalid argument was provided";
   break;
  case XBEE_ERANGE:
   str = "Requested data falls outside the boundaries";
   break;
  case XBEE_ELENGTH:
   str = "A length mis-match occured";
   break;
  case XBEE_EFAILED:
   str = "A function call failed";
   break;
  case XBEE_ETIMEOUT:
   str = "A timeout occured";
   break;
  case XBEE_EWOULDBLOCK:
   str = "The call would block, but something is marked 'non-blocking'";
   break;
  case XBEE_EINUSE:
   str = "A the item request is currently in use";
   break;
  case XBEE_EEXISTS:
   str = "An item already exists by that name or identifier";
   break;
  case XBEE_ENOTEXISTS:
   str = "The requested item does not exist";
   break;
  case XBEE_ENOFREEFRAMEID:
   str = "There is currently no free frame ID that can be used for the request";
   break;
  case XBEE_ESTALE:
   str = "Stale information was used during this function call";
   break;
  case XBEE_ENOTIMPLEMENTED:
   str = "The called functionality has not yet been implemented";
   break;
  case XBEE_ETX:
   str = "Transmission failed (check the retVal)";
   break;
  case XBEE_EREMOTE:
   str = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
   break;
  case XBEE_ESLEEPING:
   str = "The given connection is not currently awake";
   break;
  case XBEE_ECATCHALL:
   str = "The given connection is a catch-all connection";
   break;
 }
 return str;
}

canonical_original_code:
char *xbee_errorToStr(enum xbee_errors error) {
 char *str = "Unknown error...";
 switch (error) {
  case XBEE_ENONE:
   str = "No error";
   break;
  case XBEE_EUNKNOWN:
  default:
   str = "Unknown error...";
   break;
  case XBEE_ENOMEM:
   str = "Out of memory";
   break;
  case XBEE_ESELECT:
   str = "select() failed";
   break;
  case XBEE_ESELECTINTERRUPTED:
   str = "select() was interrupted";
   break;
  case XBEE_EEOF:
   str = "An EOF character was read";
   break;
  case XBEE_EIO:
   str = "An I/O request failed";
   break;
  case XBEE_ESEMAPHORE:
   str = "A semaphore error occured";
   break;
  case XBEE_EMUTEX:
   str = "A mutex error occured";
   break;
  case XBEE_ETHREAD:
   str = "A pthread error occured";
   break;
  case XBEE_ELINKEDLIST:
   str = "A linkedlist error occured";
   break;
  case XBEE_ESETUP:
   str = "Setup failed";
   break;
  case XBEE_EMISSINGPARAM:
   str = "A crucial parameter was missing";
   break;
  case XBEE_EINVAL:
   str = "An invalid argument was provided";
   break;
  case XBEE_ERANGE:
   str = "Requested data falls outside the boundaries";
   break;
  case XBEE_ELENGTH:
   str = "A length mis-match occured";
   break;
  case XBEE_EFAILED:
   str = "A function call failed";
   break;
  case XBEE_ETIMEOUT:
   str = "A timeout occured";
   break;
  case XBEE_EWOULDBLOCK:
   str = "The call would block, but something is marked 'non-blocking'";
   break;
  case XBEE_EINUSE:
   str = "A the item request is currently in use";
   break;
  case XBEE_EEXISTS:
   str = "An item already exists by that name or identifier";
   break;
  case XBEE_ENOTEXISTS:
   str = "The requested item does not exist";
   break;
  case XBEE_ENOFREEFRAMEID:
   str = "There is currently no free frame ID that can be used for the request";
   break;
  case XBEE_ESTALE:
   str = "Stale information was used during this function call";
   break;
  case XBEE_ENOTIMPLEMENTED:
   str = "The called functionality has not yet been implemented";
   break;
  case XBEE_ETX:
   str = "Transmission failed (check the retVal)";
   break;
  case XBEE_EREMOTE:
   str = "An error occured on the remote host, or an error was encountered while communicating with the remote host";
   break;
  case XBEE_ESLEEPING:
   str = "The given connection is not currently awake";
   break;
  case XBEE_ECATCHALL:
   str = "The given connection is a catch-all connection";
   break;
 }
 return str;
}

variable_types: enum xbee_errors { XBEE_ENONE=0, XBEE_EUNKNOWN=-1, XBEE_ENOMEM=-2, XBEE_ESELECT=-3, XBEE_ESELECTINTERRUPTED=-4, XBEE_EEOF=-5, XBEE_EIO=-6, XBEE_ESEMAPHORE=-7, XBEE_EMUTEX=-8, XBEE_ETHREAD=-9, XBEE_ELINKEDLIST=-10, XBEE_ESETUP=-11, XBEE_EMISSINGPARAM=-12, XBEE_EINVAL=-13, XBEE_ERANGE=-14, XBEE_ELENGTH=-15, XBEE_EFAILED=-18, XBEE_ETIMEOUT=-17, XBEE_EWOULDBLOCK=-16, XBEE_EINUSE=-19, XBEE_EEXISTS=-20, XBEE_ENOTEXISTS=-21, XBEE_ENOFREEFRAMEID=-22, XBEE_ESTALE=-23, XBEE_ENOTIMPLEMENTED=-24, XBEE_ETX=-25, XBEE_EREMOTE=-26, XBEE_ESLEEPING=-27, XBEE_ECATCHALL=-28 }

variable_types:
str
char *

return_type: char *


repo: berlincount/vchat-client

decompiled_code:
void command_reconnect()
{
status = 0;
wantreconnect = 1;
ownquit = 0;
}

canonical_decompiled_code:
void func0()
{
status = 0;
wantreconnect = 1;
ownquit = 0;
}

original_code:
static void
command_reconnect(char *tail)
{
  status = 0;
  wantreconnect = 1;
  ownquit = 0;
}

variable_types:
tail
char *


decompiled_code:
__int64 command_version()
{
flushout();
writeout(vchat_cl_version);
writeout(vchat_ui_version);
writeout(vchat_io_version);
writeout(vchat_us_version);
writeout(vchat_cm_version);
writeout(vchat_ssl_version);
writeout(vchat_ssl_version_external);
return showout();
}

canonical_decompiled_code:
__int64 func1()
{
flushout();
writeout(vchat_cl_version);
writeout(vchat_ui_version);
writeout(vchat_io_version);
writeout(vchat_us_version);
writeout(vchat_cm_version);
writeout(vchat_ssl_version);
writeout(vchat_ssl_version_external);
return showout();
}

original_code:
void
command_version(char *tail)
{
  flushout();
  writeout (vchat_cl_version);
  writeout (vchat_ui_version);
  writeout (vchat_io_version);
  writeout (vchat_us_version);
  writeout (vchat_cm_version);
  writeout (vchat_ssl_version);
  writeout (vchat_ssl_version_external);
  showout();
}


decompiled_code:
__int64 __fastcall command_none(const char *a1)
{
snprintf(tmpstr, 0x400uLL, " Unknown client command: %s ", a1);
flushout();
writeout(tmpstr);
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
snprintf(tmpstr, 0x400uLL, " Unknown client command: %s ", a1);
flushout();
writeout(tmpstr);
return showout();
}

original_code:
static void
command_none(char *line) {
    snprintf(tmpstr, 1024, "  Unknown client command: %s ", line);
    {flushout();writeout(tmpstr);showout();};
}

variable_types:
line
char *


decompiled_code:
__int64 __fastcall command_quit(const char *a1)
{
__int64 result; // rax

snprintf(tmpstr, 0x400uLL, ".x %s", a1);
networkoutput(tmpstr);
result = writechan(tmpstr);
status = 0;
ownquit = 1;
return result;
}

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

snprintf(tmpstr, 0x400uLL, ".x %s", a1);
networkoutput(tmpstr);
result = writechan(tmpstr);
status = 0;
ownquit = 1;
return result;
}

original_code:
static void
command_quit(char *tail)
{
  snprintf (tmpstr, 1024, ".x %s", tail);
  networkoutput (tmpstr);
  writechan (tmpstr);
  status = 0;
  ownquit = 1;
}


dothink

decompiled_code:
__int64 __fastcall dothink(const char *a1, char a2)
{
const char *i; // r12
const char *v3; // rdx

for ( i = a1; *i == 32; ++i )
;
snprintf(tmpstr, 0x400uLL, ".%c %s", (unsigned int)a2, i);
networkoutput(tmpstr);
if ( a2 == 79 )
v3 = (const char *)getformatstr(33LL);
else
v3 = (const char *)getformatstr(32LL);
snprintf(tmpstr, 0x400uLL, v3, i);
return writechan(tmpstr);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, char a2)
{
const char *i; // r12
const char *v3; // rdx

for ( i = a1; *i == 32; ++i )
;
snprintf(tmpstr, 0x400uLL, ".%c %s", (unsigned int)a2, i);
networkoutput(tmpstr);
if ( a2 == 79 )
v3 = (const char *)getformatstr(33LL);
else
v3 = (const char *)getformatstr(32LL);
snprintf(tmpstr, 0x400uLL, v3, i);
return writechan(tmpstr);
}

original_code:
static void
dothink( char *tail, char nice )
{
  while( *tail == ' ' ) tail++;
  snprintf (tmpstr, 1024, ".%c %s", nice, tail);
  networkoutput (tmpstr);
  snprintf (tmpstr, 1024, nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) : getformatstr(FS_TXPUBTHOUGHT), tail);
  writechan (tmpstr);
}

canonical_original_code:
static void dothink(char *tail, char nice)
{
  while( *tail == ' ' ) tail++;
  snprintf (tmpstr, 1024, ".%c %s", nice, tail);
  networkoutput (tmpstr);
  snprintf (tmpstr, 1024, nice == 'O' ? getformatstr(FS_TXPUBNTHOUGHT) : getformatstr(FS_TXPUBTHOUGHT), tail);
  writechan (tmpstr);
}

variable_types: nice char


decompiled_code:
__int64 __fastcall command_flt(unsigned __int8 *a1)
{
__int64 result; // rax
_BYTE *v2; // rsi

while ( 1 )
{
result = *a1;
if ( (_BYTE)result != 32 )
break;
++a1;
}
v2 = a1 + 1;
if ( (_BYTE)result )
{
while ( *v2 == 32 )
++v2;
if ( *v2 )
result = addfilter((unsigned int)(char)result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
__int64 result; // rax
_BYTE *v2; // rsi

while ( 1 )
{
result = *a1;
if ( (_BYTE)result != 32 )
break;
++a1;
}
v2 = a1 + 1;
if ( (_BYTE)result )
{
while ( *v2 == 32 )
++v2;
if ( *v2 )
result = addfilter((unsigned int)(char)result);
}
return result;
}

original_code:
static void
command_flt(char *tail){
  char colour;
  while(*tail==' ') tail++;
  colour = *tail++;
  while( colour && *tail == ' ') tail++;
  if( colour && *tail) {
      addfilter( colour, tail);
  }
}

variable_types: colour char


decompiled_code:
// attributes: thunk
__int64 command_dict()
{
return ul_add_to_dict();
}

canonical_decompiled_code:
__int64 func6()
{
return ul_add_to_dict();
}

original_code:
void
command_dict(char *tail)
{
  ul_add_to_dict(tail);
}


decompiled_code:
__int64 __fastcall command_user(_BYTE *a1)
{
_BYTE *v1; // r12
char i; // al
_BYTE *v3; // rbx
const char *v4; // rax
const char *v5; // rax
const char *v7; // rax

v1 = a1;
for ( i = *a1; i == 32; ++v1 )
i = v1[1];
if ( i )
{
v3 = (_BYTE *)ul_match_user(v1);
if ( *v3 )
{
v4 = (const char *)getformatstr(16LL);
snprintf(tmpstr, 0x400uLL, v4, v1, v3);
}
else
{
v7 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v7, " No user matched that regex. ");
}
}
else
{
v5 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v5, " Which user? ");
}
flushout();
writeout(tmpstr);
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
_BYTE *v1; // r12
char i; // al
_BYTE *v3; // rbx
const char *v4; // rax
const char *v5; // rax
const char *v7; // rax

v1 = a1;
for ( i = *a1; i == 32; ++v1 )
i = v1[1];
if ( i )
{
v3 = (_BYTE *)ul_match_user(v1);
if ( *v3 )
{
v4 = (const char *)getformatstr(16LL);
snprintf(tmpstr, 0x400uLL, v4, v1, v3);
}
else
{
v7 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v7, " No user matched that regex. ");
}
}
else
{
v5 = (const char *)getformatstr(3LL);
snprintf(tmpstr, 0x400uLL, v5, " Which user? ");
}
flushout();
writeout(tmpstr);
return showout();
}

original_code:
static void
command_user(char *tail)
{
  while( *tail == ' ') tail++;
  if( *tail ) {
      char * out = ul_match_user( tail);
      if( *out ) {
          snprintf( tmpstr, 1024, getformatstr(FS_USMATCH), tail, out);
      } else {
          snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  No user matched that regex. ");
      }
  } else {
      snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  Which user? ");
  }
  {flushout();writeout(tmpstr);showout();};
}

canonical_original_code:
static void command_user(char *tail)
{
  while( *tail == ' ') tail++;
  if( *tail ) {
      char *out = ul_match_user( tail);
      if( *out ) {
          snprintf( tmpstr, 1024, getformatstr(FS_USMATCH), tail, out);
      } else {
          snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  No user matched that regex. ");
      }
  } else {
      snprintf( tmpstr, 1024, getformatstr(FS_ERR), "  Which user? ");
  }
  {flushout();writeout(tmpstr);showout();};
}

variable_types:
out
char *


decompiled_code:
__int64 __fastcall command_format(const char *a1)
{
const char *v1; // rbp
const char *v2; // rax
char *v3; // r12
const char *v4; // rax
struct stat v6; // [rsp+0h] [rbp-10A8h] BYREF
char s[4120]; // [rsp+90h] [rbp-1018h] BYREF

v1 = a1;
flushout();
if ( *a1 == 32 )
{
do
++v1;
while ( *v1 == 32 );
}
v2 = (const char *)tilde_expand(v1);
v3 = (char *)v2;
if ( v2 && !stat(v2, &v6)
|| (snprintf(s, 0x1000uLL, "~/.vchat/sample-%s.fmt", v1),
free(v3),
v4 = (const char *)tilde_expand(v1),
(v3 = (char *)v4) != 0LL)
&& !stat(v4, &v6) )
{
loadformats(v3);
}
writeout(" Sort of done. ");
free(v3);
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
const char *v1; // rbp
const char *v2; // rax
char *v3; // r12
const char *v4; // rax
struct stat v6; // [rsp+0h] [rbp-10A8h] BYREF
char s[4120]; // [rsp+90h] [rbp-1018h] BYREF

v1 = a1;
flushout();
if ( *a1 == 32 )
{
do
++v1;
while ( *v1 == 32 );
}
v2 = (const char *)tilde_expand(v1);
v3 = (char *)v2;
if ( v2 && !stat(v2, &v6)
|| (snprintf(s, 0x1000uLL, "~/.vchat/sample-%s.fmt", v1),
free(v3),
v4 = (const char *)tilde_expand(v1),
(v3 = (char *)v4) != 0LL)
&& !stat(v4, &v6) )
{
loadformats(v3);
}
writeout(" Sort of done. ");
free(v3);
return showout();
}

original_code:
static void
command_format(char *line) {
  struct stat testexist;
  char * tildex = ((void *)0);
  flushout();
  while( *line==' ') line++;
  if(line) {
    tildex = tilde_expand( line );
    if(tildex && !stat(tildex, &testexist ))
      loadformats(tildex);
    else {
      char buf[4096];
      snprintf( buf, 4096, "~/.vchat/sample-%s.fmt", line );
      free(tildex);
      tildex = tilde_expand( line );
      if(tildex && !stat(tildex, &testexist ))
        loadformats(tildex);
    }
    writeout("  Sort of done.  ");
  } else {
    writeout("  Forgot to specify format file.  ");
  }
  free(tildex);
  showout();
}

canonical_original_code:
static void command_format(char *line) {
  struct stat testexist;
  char *tildex = ((void *)0);
  flushout();
  while( *line==' ') line++;
  if(line) {
    tildex = tilde_expand( line );
    if(tildex && !stat(tildex, &testexist ))
      loadformats(tildex);
    else {
      char buf[4096];
      snprintf( buf, 4096, "~/.vchat/sample-%s.fmt", line );
      free(tildex);
      tildex = tilde_expand( line );
      if(tildex && !stat(tildex, &testexist ))
        loadformats(tildex);
    }
    writeout("  Sort of done.  ");
  } else {
    writeout("  Forgot to specify format file.  ");
  }
  free(tildex);
  showout();
}

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

variable_types:
tildex
char *

variable_types:
buf
char [4096]


decompiled_code:
__int64 __fastcall command_clflt(_BYTE *a1)
{
while ( *a1 == 32 )
++a1;
return clearfilters((unsigned int)(char)*a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1)
{
while ( *a1 == 32 )
++a1;
return clearfilters((unsigned int)(char)*a1);
}

original_code:
static void
command_clflt (char *tail) {
  while( *tail == ' ') tail++;
  clearfilters( *tail );
}

canonical_original_code:
static void command_clflt(char *tail) {
  while( *tail == ' ') tail++;
  clearfilters( *tail );
}


decompiled_code:
__int64 __fastcall command_rmflt(_BYTE *a1)
{
while ( *a1 == 32 )
++a1;
return removefilter();
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1)
{
while ( *a1 == 32 )
++a1;
return removefilter();
}

original_code:
static void
command_rmflt (char *tail) {
  while( *tail == ' ') tail++;
  removefilter( tail );
}

canonical_original_code:
static void command_rmflt(char *tail) {
  while( *tail == ' ') tail++;
  removefilter( tail );
}


decompiled_code:
// attributes: thunk
__int64 command_lsflt()
{
return listfilters();
}

canonical_decompiled_code:
__int64 func11()
{
return listfilters();
}

original_code:
static void
command_lsflt (char *tail) {
  listfilters();
}

canonical_original_code:
static void command_lsflt(char *tail) {
  listfilters();
}


privatemessagetx

decompiled_code:
__int64 __fastcall privatemessagetx(_BYTE *a1)
{
_BYTE *v1; // rbp
char i; // dl
_BYTE *v3; // rax
char v4; // cl
const char *v5; // rdi
__int64 result; // rax
_BYTE *v7; // rbx
const char *v8; // rax

v1 = a1;
for ( i = *a1; i == 32; ++v1 )
i = v1[1];
if ( (i & 0xDF) != 0 )
{
v3 = v1;
do
v4 = *++v3;
while ( (v4 & 0xDF) != 0 );
}
else
{
v4 = i;
v3 = v1;
}
if ( v4 && i )
{
*v3 = 0;
v7 = v3 + 1;
snprintf(tmpstr, 0x400uLL, ".m %s %s", v1, v3 + 1);
networkoutput(tmpstr);
v8 = (const char *)getformatstr(30LL);
snprintf(tmpstr, 0x400uLL, v8, v1, v7);
writepriv(tmpstr, 0LL);
result = ul_private_action(v1);
}
else
{
flushout();
v5 = " Won't send empty message. ";
if ( !*v1 )
v5 = " Recipient missing. ";
writeout(v5);
result = showout();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1)
{
_BYTE *v1; // rbp
char i; // dl
_BYTE *v3; // rax
char v4; // cl
const char *v5; // rdi
__int64 result; // rax
_BYTE *v7; // rbx
const char *v8; // rax

v1 = a1;
for ( i = *a1; i == 32; ++v1 )
i = v1[1];
if ( (i & 0xDF) != 0 )
{
v3 = v1;
do
v4 = *++v3;
while ( (v4 & 0xDF) != 0 );
}
else
{
v4 = i;
v3 = v1;
}
if ( v4 && i )
{
*v3 = 0;
v7 = v3 + 1;
snprintf(tmpstr, 0x400uLL, ".m %s %s", v1, v3 + 1);
networkoutput(tmpstr);
v8 = (const char *)getformatstr(30LL);
snprintf(tmpstr, 0x400uLL, v8, v1, v7);
writepriv(tmpstr, 0LL);
result = ul_private_action(v1);
}
else
{
flushout();
v5 = " Won't send empty message. ";
if ( !*v1 )
v5 = " Recipient missing. ";
writeout(v5);
result = showout();
}
return result;
}

original_code:
static void
privatemessagetx ( char *tail ) {
  char *mesg;
  while( *tail==' ') tail++;
  mesg = tail;
  while ( *mesg && *mesg!=' ') mesg++;
  if(*tail && *mesg) {
      *mesg++ = '\0';
      snprintf (tmpstr, 1024, ".m %s %s", tail, mesg);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPRIVMSG), tail, mesg);
      writepriv (tmpstr, 0);
      ul_private_action(tail);
  } else {
      {flushout();writeout(*tail ? "  Won't send empty message. ":"  Recipient missing. ");showout();};
  }
}

canonical_original_code:
static void privatemessagetx(char *tail) {
  char *mesg;
  while( *tail==' ') tail++;
  mesg = tail;
  while ( *mesg && *mesg!=' ') mesg++;
  if(*tail && *mesg) {
      *mesg++ = '\0';
      snprintf (tmpstr, 1024, ".m %s %s", tail, mesg);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPRIVMSG), tail, mesg);
      writepriv (tmpstr, 0);
      ul_private_action(tail);
  } else {
      {flushout();writeout(*tail ? "  Won't send empty message. ":"  Recipient missing. ");showout();};
  }
}

variable_types:
mesg
char *


decompiled_code:
// attributes: thunk
__int64 __fastcall command_pm(_BYTE *a1)
{
return privatemessagetx(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(_BYTE *a1)
{
return func12(a1);
}

original_code:
static void
command_pm (char *tail)
{
  privatemessagetx( tail );
}

canonical_original_code:
static void command_pm(char *tail)
{
  privatemessagetx( tail );
}


decompiled_code:
__int64 __fastcall command_query(char *s)
{
char *i; // rbp
char *v2; // rbx

for ( i = s; *i == 32; ++i )
;
v2 = strchr(i, 32);
if ( v2 )
{
privatemessagetx(i);
*v2 = 0;
}
return handlequery(i);
}

canonical_decompiled_code:
__int64 __fastcall func14(char *s)
{
char *i; // rbp
char *v2; // rbx

for ( i = s; *i == 32; ++i )
;
v2 = strchr(i, 32);
if ( v2 )
{
func12(i);
*v2 = 0;
}
return handlequery(i);
}

original_code:
void
command_query(char *tail)
{
  char *msg;
  while( *tail == ' ') tail++;
  if((msg = strchr(tail, ' '))) {
    privatemessagetx( tail );
    *msg = 0;
  }
  handlequery( tail );
}

variable_types:
msg
char *


doaction

decompiled_code:
__int64 __fastcall doaction(_BYTE *a1)
{
_BYTE *v1; // rbx
char i; // al
__int64 v3; // r12
const char *v4; // rax
__int64 result; // rax

v1 = a1;
for ( i = *a1; i == 32; ++v1 )
i = v1[1];
if ( i )
{
snprintf(tmpstr, 0x400uLL, ".a %s", v1);
networkoutput(tmpstr);
v3 = own_nick_get();
v4 = (const char *)getformatstr(35LL);
snprintf(tmpstr, 0x400uLL, v4, v3, v1);
result = writechan(tmpstr);
}
else
{
flushout();
writeout(" You do nothing. ");
result = showout();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(_BYTE *a1)
{
_BYTE *v1; // rbx
char i; // al
__int64 v3; // r12
const char *v4; // rax
__int64 result; // rax

v1 = a1;
for ( i = *a1; i == 32; ++v1 )
i = v1[1];
if ( i )
{
snprintf(tmpstr, 0x400uLL, ".a %s", v1);
networkoutput(tmpstr);
v3 = own_nick_get();
v4 = (const char *)getformatstr(35LL);
snprintf(tmpstr, 0x400uLL, v4, v3, v1);
result = writechan(tmpstr);
}
else
{
flushout();
writeout(" You do nothing. ");
result = showout();
}
return result;
}

original_code:
static void
doaction( char *tail )
{
  while( *tail == ' ' ) tail++;
  if( *tail ) {
      snprintf (tmpstr, 1024, ".a %s", tail);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBACTION), own_nick_get(), tail);
      writechan (tmpstr);
  } else {
      {flushout();writeout("  You do nothing. ");showout();};
  }
}

canonical_original_code:
static void doaction(char *tail)
{
  while( *tail == ' ' ) tail++;
  if( *tail ) {
      snprintf (tmpstr, 1024, ".a %s", tail);
      networkoutput (tmpstr);
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBACTION), own_nick_get(), tail);
      writechan (tmpstr);
  } else {
      {flushout();writeout("  You do nothing. ");showout();};
  }
}


decompiled_code:
// attributes: thunk
__int64 __fastcall command_action(_BYTE *a1)
{
return doaction(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(_BYTE *a1)
{
return func15(a1);
}

original_code:
static void
command_action(char *tail)
{
  doaction( tail);
}


decompiled_code:
__int64 __fastcall output_default(__int64 a1)
{
__int64 v1; // r12
const char *v2; // rax

v1 = own_nick_get();
v2 = (const char *)getformatstr(28LL);
snprintf(tmpstr, 0x400uLL, v2, v1, a1);
networkoutput(a1);
return writechan(tmpstr);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 v1; // r12
const char *v2; // rax

v1 = own_nick_get();
v2 = (const char *)getformatstr(28LL);
snprintf(tmpstr, 0x400uLL, v2, v1, a1);
networkoutput(a1);
return writechan(tmpstr);
}

original_code:
static void
output_default(char *line ) {
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBMSG), own_nick_get(), line);
      networkoutput (line);
      writechan (tmpstr);
}

canonical_original_code:
static void output_default(char *line) {
      snprintf (tmpstr, 1024, getformatstr(FS_TXPUBMSG), own_nick_get(), line);
      networkoutput (line);
      writechan (tmpstr);
}


translatecommand

original_code:
static int
translatecommand( char **cmd)
{
  int result;
  int cut = 0;
  int maxcut = 0;
  while( (*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) maxcut++;
  if( maxcut ) maxcut--;
  do {
      for( result = 0;
             (result != COMMAND_NONE) &&
             (strncasecmp(*cmd, commandtable[result].name, commandtable[result].len -
               ((commandtable[result].len - maxcut - cut > 0) ? cut : 0)));
           result++);
  } while ((cut < commandtable[0].len) && (commandtable[result].number == COMMAND_NONE) && (++cut));
  (*cmd) += commandtable[result].len;
  if( commandtable[result].number != COMMAND_NONE )
      (*cmd) -= cut;
  return result;
}

canonical_original_code:
static int translatecommand(char **cmd)
{
  int result;
  int cut = 0;
  int maxcut = 0;
  while( (*cmd)[maxcut] && ((*cmd)[maxcut] != 0x20) && ((*cmd)[maxcut] != '\n')) maxcut++;
  if( maxcut ) maxcut--;
  do {
      for( result = 0;
             (result != COMMAND_NONE) &&
             (strncasecmp(*cmd, commandtable[result].name, commandtable[result].len -
               ((commandtable[result].len - maxcut - cut > 0) ? cut : 0)));
           result++);
  } while ((cut < commandtable[0].len) && (commandtable[result].number == COMMAND_NONE) && (++cut));
  (*cmd) += commandtable[result].len;
  if( commandtable[result].number != COMMAND_NONE )
      (*cmd) -= cut;
  return result;
}

variable_types:
cmd
char **

variable_types: result int

variable_types: cut int

variable_types: maxcut int


decompiled_code:
__int64 __fastcall command_help(const char *a1)
{
char v1; // dl
const char *v2; // rax
char **v3; // rbx
int v4; // eax
__int64 v5; // rbx
__int64 v6; // rbp
char *v7; // rdi
int *v8; // rbp
const char *v9; // rax
const char *v10; // rsi
char v11; // al
bool v12; // zf
char *v13; // rdx
const char *v14; // rax
char v15; // cl
char v16; // cl
const char *v18; // [rsp+8h] [rbp-20h] BYREF

v18 = a1;
flushout();
v1 = *a1;
if ( *a1 == 32 )
{
v2 = v18 + 1;
do
{
v18 = v2;
v1 = *v2++;
}
while ( v1 == 32 );
}
if ( !v1 )
{
v3 = &off_AE0;
if ( commandtable[0] != 19 )
{
do
{
if ( *v3 )
writeout(*v3);
v3 += 6;
}
while ( *((_DWORD *)v3 - 8) != 19 );
}
return showout();
}
v4 = translatecommand(&v18);
if ( v4 != 19 )
{
v5 = v4;
v6 = 12LL * v4;
snprintf(tmpstr, 0x400uLL, "Help on command: %s", &s2[v6 * 4]);
writeout(tmpstr);
writeout(" ");
v7 = (&off_AE0)[6 * v5];
v8 = &commandtable[v6];
if ( v7 )
{
v9 = (const char *)*((_QWORD *)v8 + 5);
if ( v9 )
{
v18 = (const char *)*((_QWORD *)v8 + 5);
goto LABEL_14;
}
writeout(v7);
}
v9 = (const char *)qword_AE8[6 * v5];
v18 = v9;
if ( !v9 )
return showout();
LABEL_14:
if ( *v9 )
{
v10 = v18;
v11 = *v18;
do
{
if ( v11 == 10 || (v12 = v11 == 0, v13 = tmpstr, v14 = v10 + 1, v12) )
{
v13 = tmpstr;
}
else
{
do
{
v18 = v14;
v15 = *(v14 - 1);
v10 = v14;
++v13;
++v14;
*(v13 - 1) = v15;
v16 = *(v14 - 1);
}
while ( v16 && v16 != 10 );
}
*v13 = 0;
if ( *v10 == 10 )
v18 = v10 + 1;
writeout(tmpstr);
v10 = v18;
v11 = *v18;
}
while ( *v18 );
}
return showout();
}
command_help(" ");
return showout();
}

canonical_decompiled_code:
__int64 __fastcall func19(const char *a1)
{
char v1; // dl
const char *v2; // rax
char **v3; // rbx
int v4; // eax
__int64 v5; // rbx
__int64 v6; // rbp
char *v7; // rdi
int *v8; // rbp
const char *v9; // rax
const char *v10; // rsi
char v11; // al
bool v12; // zf
char *v13; // rdx
const char *v14; // rax
char v15; // cl
char v16; // cl
const char *v18; // [rsp+8h] [rbp-20h] BYREF

v18 = a1;
flushout();
v1 = *a1;
if ( *a1 == 32 )
{
v2 = v18 + 1;
do
{
v18 = v2;
v1 = *v2++;
}
while ( v1 == 32 );
}
if ( !v1 )
{
v3 = &off_AE0;
if ( commandtable[0] != 19 )
{
do
{
if ( *v3 )
writeout(*v3);
v3 += 6;
}
while ( *((_DWORD *)v3 - 8) != 19 );
}
return showout();
}
v4 = func18(&v18);
if ( v4 != 19 )
{
v5 = v4;
v6 = 12LL * v4;
snprintf(tmpstr, 0x400uLL, "Help on command: %s", &s2[v6 * 4]);
writeout(tmpstr);
writeout(" ");
v7 = (&off_AE0)[6 * v5];
v8 = &commandtable[v6];
if ( v7 )
{
v9 = (const char *)*((_QWORD *)v8 + 5);
if ( v9 )
{
v18 = (const char *)*((_QWORD *)v8 + 5);
goto LABEL_14;
}
writeout(v7);
}
v9 = (const char *)qword_AE8[6 * v5];
v18 = v9;
if ( !v9 )
return showout();
LABEL_14:
if ( *v9 )
{
v10 = v18;
v11 = *v18;
do
{
if ( v11 == 10 || (v12 = v11 == 0, v13 = tmpstr, v14 = v10 + 1, v12) )
{
v13 = tmpstr;
}
else
{
do
{
v18 = v14;
v15 = *(v14 - 1);
v10 = v14;
++v13;
++v14;
*(v13 - 1) = v15;
v16 = *(v14 - 1);
}
while ( v16 && v16 != 10 );
}
*v13 = 0;
if ( *v10 == 10 )
v18 = v10 + 1;
writeout(tmpstr);
v10 = v18;
v11 = *v18;
}
while ( *v18 );
}
return showout();
}
func19(" ");
return showout();
}

original_code:
static void
command_help (char *line) {
  flushout( );
  while( *line==' ') line++;
  if( *line ) {
      int i;
      if( ( i = translatecommand( &line ) ) != COMMAND_NONE ) {
          snprintf( tmpstr, 1024, "Help on command: %s", commandtable[i].name);
          writeout( tmpstr );
          writeout(" ");
          if( commandtable[i].short_help && !commandtable[i].help )
              writeout(commandtable[i].short_help );
          line = commandtable[i].help;
          if( line ) {
            while( *line ) {
              char *tmp = tmpstr;
              while( *line && (*line != '\n') )
                  *tmp++ = *line++;
              *tmp = '\0'; if( *line == '\n') line++;
              writeout ( tmpstr );
            }
          }
      } else {
          command_help( " " );
      }
  } else {
      int i;
      for( i = 0; commandtable[i].number != COMMAND_NONE; i++ ) {
          if( commandtable[i].short_help )
              writeout( commandtable[i].short_help );
      }
  }
  showout();
}

canonical_original_code:
static void command_help(char *line) {
  flushout( );
  while( *line==' ') line++;
  if( *line ) {
      int i;
      if( ( i = translatecommand( &line ) ) != COMMAND_NONE ) {
          snprintf( tmpstr, 1024, "Help on command: %s", commandtable[i].name);
          writeout( tmpstr );
          writeout(" ");
          if( commandtable[i].short_help && !commandtable[i].help )
              writeout(commandtable[i].short_help );
          line = commandtable[i].help;
          if( line ) {
            while( *line ) {
              char *tmp = tmpstr;
              while( *line && (*line != '\n') )
                  *tmp++ = *line++;
              *tmp = '\0'; if( *line == '\n') line++;
              writeout ( tmpstr );
            }
          }
      } else {
          command_help( " " );
      }
  } else {
      int i;
      for( i = 0; commandtable[i].number != COMMAND_NONE; i++ ) {
          if( commandtable[i].short_help )
              writeout( commandtable[i].short_help );
      }
  }
  showout();
}

variable_types: i int

variable_types:
tmp
char *


handleline

decompiled_code:
__int64 __fastcall handleline(__int64 a1)
{
char v2; // si
const char *v3; // rax
int v4; // eax
const char *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = (const char *)a1;
if ( *(_BYTE *)a1 == 46 )
{
v2 = *(_BYTE *)(a1 + 1);
if ( v2 == 109 )
return privatemessagetx((_BYTE *)(a1 + 2));
if ( *(char *)(a1 + 1) > 109 )
{
if ( v2 != 111 )
{
if ( v2 == 120 )
ownquit = 1;
goto LABEL_9;
}
}
else if ( v2 != 79 )
{
if ( v2 == 97 )
return doaction((_BYTE *)(a1 + 2));
if ( v2 == 46 )
{
if ( *(_BYTE *)(a1 + 2) != 109 )
return output_default(a1);
flushout();
writeout("? You probably misstyped ?");
writeout(" ");
writeout(v5);
return showout();
}
LABEL_9:
v3 = (const char *)getformatstr(36LL);
snprintf(tmpstr, 0x400uLL, v3, a1);
writechan(tmpstr);
return networkoutput(v5);
}
return dothink((const char *)(a1 + 2), v2);
}
if ( *(_BYTE *)a1 != 47 )
return output_default(a1);
v5 = (const char *)(a1 + 1);
v4 = translatecommand(&v5);
return ((__int64 (__fastcall *)(const char *))*(&off_AD8 + 6 * v4))(v5);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
char v2; // si
const char *v3; // rax
int v4; // eax
const char *v5; // [rsp+8h] [rbp-10h] BYREF

v5 = (const char *)a1;
if ( *(_BYTE *)a1 == 46 )
{
v2 = *(_BYTE *)(a1 + 1);
if ( v2 == 109 )
return func12((_BYTE *)(a1 + 2));
if ( *(char *)(a1 + 1) > 109 )
{
if ( v2 != 111 )
{
if ( v2 == 120 )
ownquit = 1;
goto LABEL_9;
}
}
else if ( v2 != 79 )
{
if ( v2 == 97 )
return func15((_BYTE *)(a1 + 2));
if ( v2 == 46 )
{
if ( *(_BYTE *)(a1 + 2) != 109 )
return func17(a1);
flushout();
writeout("? You probably misstyped ?");
writeout(" ");
writeout(v5);
return showout();
}
LABEL_9:
v3 = (const char *)getformatstr(36LL);
snprintf(tmpstr, 0x400uLL, v3, a1);
writechan(tmpstr);
return networkoutput(v5);
}
return func4((const char *)(a1 + 2), v2);
}
if ( *(_BYTE *)a1 != 47 )
return func17(a1);
v5 = (const char *)(a1 + 1);
v4 = func18(&v5);
return ((__int64 (__fastcall *)(const char *))*(&off_AD8 + 6 * v4))(v5);
}

original_code:
void
handleline (char *line)
{
  switch ( line[0] )
  {
  case '.':
      switch ( line[1] ) {
      case 'm':
          privatemessagetx( line+2 );
          break;
      case 'a':
          doaction( line+2 );
          break;
      case '.':
          if( line[2] != 'm' ) {
              output_default( line );
          } else {
              flushout( );
              writeout("? You probably misstyped ?");
              writeout(" ");
              writeout(line );
              showout( );
          }
          break;
      case 'o':
      case 'O':
          dothink( line + 2, line[1] );
          break;
      case 'x':
          ownquit = 1;
      default:
          snprintf (tmpstr, 1024, getformatstr(FS_COMMAND), line);
          writechan (tmpstr);
          networkoutput (line);
          break;
      }
      break;
  case '/':
      line++;
      commandtable[translatecommand(&line)].handler(line);
      break;
  default:
      output_default( line );
      break;
  }
}

canonical_original_code:
void handleline(char *line)
{
  switch ( line[0] )
  {
  case '.':
      switch ( line[1] ) {
      case 'm':
          privatemessagetx( line+2 );
          break;
      case 'a':
          doaction( line+2 );
          break;
      case '.':
          if( line[2] != 'm' ) {
              output_default( line );
          } else {
              flushout( );
              writeout("? You probably misstyped ?");
              writeout(" ");
              writeout(line );
              showout( );
          }
          break;
      case 'o':
      case 'O':
          dothink( line + 2, line[1] );
          break;
      case 'x':
          ownquit = 1;
      default:
          snprintf (tmpstr, 1024, getformatstr(FS_COMMAND), line);
          writechan (tmpstr);
          networkoutput (line);
          break;
      }
      break;
  case '/':
      line++;
      commandtable[translatecommand(&line)].handler(line);
      break;
  default:
      output_default( line );
      break;
  }
}


transform

repo: bernarpa/PAES

variable_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; } *

variable_types:
data
unsigned char *

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int

variable_types:
e
unsigned int

variable_types:
f
unsigned int

variable_types:
g
unsigned int

variable_types:
h
unsigned int

variable_types:
w
unsigned int [64]

variable_types: t int

variable_types:
k
unsigned int []


decompiled_code:
__int64 __fastcall sha256_write(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r12
char *v4; // rbp
__int64 result; // rax
int v6; // ecx
unsigned __int64 v7; // r13
char *v8; // rsi
unsigned __int64 v9; // r12
unsigned __int64 v10; // r13

v3 = a3;
v4 = a2;
result = *(unsigned int *)(a1 + 100);
if ( (_DWORD)result == 64 )
{
result = transform((int *)a1, (char *)(a1 + 36));
++*(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 100) = 0;
if ( !a2 )
return result;
goto LABEL_9;
}
if ( !a2 )
return result;
if ( !(_DWORD)result )
{
LABEL_9:
if ( v3 <= 0x3F )
{
v7 = (unsigned __int64)v4;
}
else
{
v7 = (unsigned __int64)&v4[((v3 - 64) & 0xFFFFFFFFFFFFFFC0LL) + 64];
do
{
v8 = v4;
v4 += 64;
result = transform((int *)a1, v8);
++*(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 100) = 0;
}
while ( v4 != (char *)v7 );
v3 &= 0x3Fu;
}
if ( v3 )
{
result = *(int *)(a1 + 100);
v9 = result + v3;
v10 = v7 - result;
do
{
if ( (int)result > 63 )
break;
*(_DWORD *)(a1 + 100) = result + 1;
*(_BYTE *)(a1 + result + 36) = *(_BYTE *)(v10 + result);
++result;
}
while ( result != v9 );
}
return result;
}
result = (int)result + 1;
if ( a3 )
{
do
{
if ( (int)result - 1 > 63 )
{
result = sha256_write(a1, 0LL, 0LL);
goto LABEL_9;
}
++v4;
*(_DWORD *)(a1 + 100) = result;
v6 = result;
*(_BYTE *)(a1 + result++ + 35) = *(v4 - 1);
--v3;
}
while ( v3 );
if ( v6 == 64 )
{
result = transform((int *)a1, (char *)(a1 + 36));
++*(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 100) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r12
char *v4; // rbp
__int64 result; // rax
int v6; // ecx
unsigned __int64 v7; // r13
char *v8; // rsi
unsigned __int64 v9; // r12
unsigned __int64 v10; // r13

v3 = a3;
v4 = a2;
result = *(unsigned int *)(a1 + 100);
if ( (_DWORD)result == 64 )
{
result = func0((int *)a1, (char *)(a1 + 36));
++*(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 100) = 0;
if ( !a2 )
return result;
goto LABEL_9;
}
if ( !a2 )
return result;
if ( !(_DWORD)result )
{
LABEL_9:
if ( v3 <= 0x3F )
{
v7 = (unsigned __int64)v4;
}
else
{
v7 = (unsigned __int64)&v4[((v3 - 64) & 0xFFFFFFFFFFFFFFC0LL) + 64];
do
{
v8 = v4;
v4 += 64;
result = func0((int *)a1, v8);
++*(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 100) = 0;
}
while ( v4 != (char *)v7 );
v3 &= 0x3Fu;
}
if ( v3 )
{
result = *(int *)(a1 + 100);
v9 = result + v3;
v10 = v7 - result;
do
{
if ( (int)result > 63 )
break;
*(_DWORD *)(a1 + 100) = result + 1;
*(_BYTE *)(a1 + result + 36) = *(_BYTE *)(v10 + result);
++result;
}
while ( result != v9 );
}
return result;
}
result = (int)result + 1;
if ( a3 )
{
do
{
if ( (int)result - 1 > 63 )
{
result = func2(a1, 0LL, 0LL);
goto LABEL_9;
}
++v4;
*(_DWORD *)(a1 + 100) = result;
v6 = result;
*(_BYTE *)(a1 + result++ + 35) = *(v4 - 1);
--v3;
}
while ( v3 );
if ( v6 == 64 )
{
result = func0((int *)a1, (char *)(a1 + 36));
++*(_DWORD *)(a1 + 32);
*(_DWORD *)(a1 + 100) = 0;
}
}
return result;
}

original_code:
void sha256_write(SHA256_CONTEXT * hd, unsigned char *inbuf, size_t inlen)
{
 if (hd->count == 64) {
  transform(hd, hd->buf);
  hd->count = 0;
  hd->nblocks++;
 }
 if (!inbuf)
  return;
 if (hd->count) {
  for (; inlen && hd->count < 64; inlen--)
   hd->buf[hd->count++] = *inbuf++;
  sha256_write(hd, ((void *)0), 0);
  if (!inlen)
   return;
 }
 while (inlen >= 64) {
  transform(hd, inbuf);
  hd->count = 0;
  hd->nblocks++;
  inlen -= 64;
  inbuf += 64;
 }
 for (; inlen && hd->count < 64; inlen--)
  hd->buf[hd->count++] = *inbuf++;
}

canonical_original_code:
void sha256_write(struct SHA256_CONTEXT *hd, unsigned char *inbuf, unsigned long inlen)
{
 if (hd->count == 64) {
  transform(hd, hd->buf);
  hd->count = 0;
  hd->nblocks++;
 }
 if (!inbuf)
  return;
 if (hd->count) {
  for (; inlen && hd->count < 64; inlen--)
   hd->buf[hd->count++] = *inbuf++;
  sha256_write(hd, ((void *)0), 0);
  if (!inlen)
   return;
 }
 while (inlen >= 64) {
  transform(hd, inbuf);
  hd->count = 0;
  hd->nblocks++;
  inlen -= 64;
  inbuf += 64;
 }
 for (; inlen && hd->count < 64; inlen--)
  hd->buf[hd->count++] = *inbuf++;
}

variable_types:
inbuf
unsigned char *

variable_types:
inlen
unsigned long

user_defined_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; }


variable_types:
t
unsigned int

variable_types:
msb
unsigned int

variable_types:
lsb
unsigned int

variable_types:
p
unsigned char *


decompiled_code:
__int64 __fastcall sha256_read(__int64 a1)
{
return a1 + 36;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return a1 + 36;
}

original_code:
unsigned char *sha256_read(SHA256_CONTEXT * hd)
{
 return hd->buf;
}

canonical_original_code:
unsigned char *sha256_read(struct SHA256_CONTEXT *hd)
{
 return hd->buf;
}

variable_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; } *

return_type: unsigned char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BOOL8 v3; // r12
__int64 *v4; // r13
__int64 v5; // rdi
void *v6; // r12
void *v7; // rsp
const char *v8; // rsi
const char *v9; // rsi
__int64 v11; // [rsp+0h] [rbp-260h] BYREF
unsigned int v12; // [rsp+Ch] [rbp-254h]
unsigned int v13; // [rsp+14h] [rbp-24Ch]
unsigned int v14; // [rsp+18h] [rbp-248h]
unsigned int v15; // [rsp+1Ch] [rbp-244h]
unsigned int v16; // [rsp+20h] [rbp-240h]
unsigned int v17; // [rsp+24h] [rbp-23Ch]
int v18; // [rsp+28h] [rbp-238h]
int v19; // [rsp+2Ch] [rbp-234h]
size_t size; // [rsp+30h] [rbp-230h]
__int64 v21; // [rsp+38h] [rbp-228h]
__int64 v22; // [rsp+40h] [rbp-220h]
__int64 v23; // [rsp+48h] [rbp-218h]
__int64 v24; // [rsp+50h] [rbp-210h]
__int64 v25; // [rsp+58h] [rbp-208h]
__int64 v26; // [rsp+60h] [rbp-200h]
__int64 v27; // [rsp+68h] [rbp-1F8h]
__int64 v28; // [rsp+70h] [rbp-1F0h]
char v29[112]; // [rsp+80h] [rbp-1E0h] BYREF
char v30[112]; // [rsp+F0h] [rbp-170h] BYREF
char v31[112]; // [rsp+160h] [rbp-100h] BYREF
char v32[144]; // [rsp+1D0h] [rbp-90h] BYREF

puts("\n***** OpenCL device informations *****\n");
if ( argc <= 1 )
{
printf("Usage: %s <cpu|gpu>\n\n", *argv);
exit(1);
}
v3 = strcmp(argv[1], s2) == 0;
printf("Device type: %s\n", (&opencl_device_str)[v3]);
clGetPlatformIDs();
printf("Number of platforms: %u\n", v12);
v4 = (__int64 *)malloc(8LL * v12);
clGetPlatformIDs();
v5 = *v4;
v26 = 4228LL;
v27 = v5;
v28 = 0LL;
clCreateContextFromType();
clGetContextInfo();
v6 = malloc(size);
clGetContextInfo();
clGetDeviceInfo();
printf("Name: %s\n", v29);
clGetDeviceInfo();
printf("Vendor: %s\n", v30);
clGetDeviceInfo();
printf("Driver version: %s\n", v31);
clGetDeviceInfo();
printf("Version: %s\n", v32);
clGetDeviceInfo();
printf("Max compute units: %u\n", v13);
clGetDeviceInfo();
printf("Max work item dimensions: %u\n", v14);
v7 = alloca(16 * ((8 * (unsigned __int64)v14 + 15) >> 4));
clGetDeviceInfo();
printarray("Max work item sizes: ", v14, &v11);
clGetDeviceInfo();
printf("Max work group size: %lu\n", v21);
clGetDeviceInfo();
printfreq("Max clock frequency: ", v15);
clGetDeviceInfo();
printf("Address bits: %u\n", v16);
clGetDeviceInfo();
printsize("Max memory allocation size: ", v22);
clGetDeviceInfo();
printsize("Global memory size: ", v23);
clGetDeviceInfo();
printsize("Max constant buffer size: ", v24);
clGetDeviceInfo();
printf("Max constant arguments: %d\n", v17);
clGetDeviceInfo();
printsize("Local memory size: ", v25);
clGetDeviceInfo();
v8 = "YES";
if ( v18 != 1 )
v8 = "NO";
printf("Error correction support: %s\n", v8);
clGetDeviceInfo();
v9 = "little endian";
if ( v19 != 1 )
v9 = "big endian";
printf("Endianness: %s\n", v9);
putchar(10);
clReleaseContext();
free(v6);
free(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BOOL8 v3; // r12
__int64 *v4; // r13
__int64 v5; // rdi
void *v6; // r12
void *v7; // rsp
const char *v8; // rsi
const char *v9; // rsi
__int64 v11; // [rsp+0h] [rbp-260h] BYREF
unsigned int v12; // [rsp+Ch] [rbp-254h]
unsigned int v13; // [rsp+14h] [rbp-24Ch]
unsigned int v14; // [rsp+18h] [rbp-248h]
unsigned int v15; // [rsp+1Ch] [rbp-244h]
unsigned int v16; // [rsp+20h] [rbp-240h]
unsigned int v17; // [rsp+24h] [rbp-23Ch]
int v18; // [rsp+28h] [rbp-238h]
int v19; // [rsp+2Ch] [rbp-234h]
size_t size; // [rsp+30h] [rbp-230h]
__int64 v21; // [rsp+38h] [rbp-228h]
__int64 v22; // [rsp+40h] [rbp-220h]
__int64 v23; // [rsp+48h] [rbp-218h]
__int64 v24; // [rsp+50h] [rbp-210h]
__int64 v25; // [rsp+58h] [rbp-208h]
__int64 v26; // [rsp+60h] [rbp-200h]
__int64 v27; // [rsp+68h] [rbp-1F8h]
__int64 v28; // [rsp+70h] [rbp-1F0h]
char v29[112]; // [rsp+80h] [rbp-1E0h] BYREF
char v30[112]; // [rsp+F0h] [rbp-170h] BYREF
char v31[112]; // [rsp+160h] [rbp-100h] BYREF
char v32[144]; // [rsp+1D0h] [rbp-90h] BYREF

puts("\n***** OpenCL device informations *****\n");
if ( argc <= 1 )
{
printf("Usage: %s <cpu|gpu>\n\n", *argv);
exit(1);
}
v3 = strcmp(argv[1], s2) == 0;
printf("Device type: %s\n", (&opencl_device_str)[v3]);
clGetPlatformIDs();
printf("Number of platforms: %u\n", v12);
v4 = (__int64 *)malloc(8LL * v12);
clGetPlatformIDs();
v5 = *v4;
v26 = 4228LL;
v27 = v5;
v28 = 0LL;
clCreateContextFromType();
clGetContextInfo();
v6 = malloc(size);
clGetContextInfo();
clGetDeviceInfo();
printf("Name: %s\n", v29);
clGetDeviceInfo();
printf("Vendor: %s\n", v30);
clGetDeviceInfo();
printf("Driver version: %s\n", v31);
clGetDeviceInfo();
printf("Version: %s\n", v32);
clGetDeviceInfo();
printf("Max compute units: %u\n", v13);
clGetDeviceInfo();
printf("Max work item dimensions: %u\n", v14);
v7 = alloca(16 * ((8 * (unsigned __int64)v14 + 15) >> 4));
clGetDeviceInfo();
func7("Max work item sizes: ", v14, &v11);
clGetDeviceInfo();
printf("Max work group size: %lu\n", v21);
clGetDeviceInfo();
func8("Max clock frequency: ", v15);
clGetDeviceInfo();
printf("Address bits: %u\n", v16);
clGetDeviceInfo();
func9("Max memory allocation size: ", v22);
clGetDeviceInfo();
func9("Global memory size: ", v23);
clGetDeviceInfo();
func9("Max constant buffer size: ", v24);
clGetDeviceInfo();
printf("Max constant arguments: %d\n", v17);
clGetDeviceInfo();
func9("Local memory size: ", v25);
clGetDeviceInfo();
v8 = "YES";
if ( v18 != 1 )
v8 = "NO";
printf("Error correction support: %s\n", v8);
clGetDeviceInfo();
v9 = "little endian";
if ( v19 != 1 )
v9 = "big endian";
printf("Endianness: %s\n", v9);
putchar(10);
clReleaseContext();
free(v6);
free(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *input_file_name = ((void *)0), *output_file_name = ((void *)0);
 aes_mode mode;
 unsigned short key_size_bits;
 char *password = ((void *)0);
 cl_uchar *password_hash = ((void *)0);
 opencl_device device;
 cl_uchar *buffer = ((void *)0);
 printf("\n\n-------- PAES --------\n\n\n");
 parse_command_line(argc, argv, &input_file_name, &output_file_name, &mode, &key_size_bits, &password, &device);
 check_arguments(mode, key_size_bits, device);
 size_t size = read_file(input_file_name, &buffer);
 if (password == ((void *)0)) {
  char *getpass(const char *prompt);
  password = getpass("\nPlease type the password: ");
 }
 password_hash = hash_password(password, key_size_bits / 8);
 printf("PARAMETERS:\n");
 printf("   Input file: %s\n", input_file_name);
 printf("   Output file: %s\n", output_file_name);
 printf("   AES mode: %s\n", get_aes_mode_name(mode));
 printf("   Key size: %u\n", key_size_bits);
 printf("   Device: %s\n", get_opencl_device_name(device));
 printf("   File size: %u bytes\n", (unsigned) size);
 printf("\n\n");
 if (apply_aes(buffer, size, device, mode, password_hash, key_size_bits) != -1)
  write_file(output_file_name, buffer, size);
 if (buffer)
  free(buffer);
 if (input_file_name)
  free(input_file_name);
 if (output_file_name)
  free(output_file_name);
 if (password)
  free(password);
 if (password_hash)
  free(password_hash);
 printf("\n\n----- It ends here... -----\n\n\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *input_file_name = ((void *)0); char *output_file_name = ((void *)0);
 unsigned int mode;
 unsigned short key_size_bits;
 char *password = ((void *)0);
 unsigned char *password_hash = ((void *)0);
 unsigned int device;
 unsigned char *buffer = ((void *)0);
 printf("\n\n-------- PAES --------\n\n\n");
 parse_command_line(argc, argv, &input_file_name, &output_file_name, &mode, &key_size_bits, &password, &device);
 check_arguments(mode, key_size_bits, device);
 unsigned long size = read_file(input_file_name, &buffer);
 if (password == ((void *)0)) {
  char *getpass(char *prompt);
  password = getpass("\nPlease type the password: ");
 }
 password_hash = hash_password(password, key_size_bits / 8);
 printf("PARAMETERS:\n");
 printf("   Input file: %s\n", input_file_name);
 printf("   Output file: %s\n", output_file_name);
 printf("   AES mode: %s\n", get_aes_mode_name(mode));
 printf("   Key size: %u\n", key_size_bits);
 printf("   Device: %s\n", get_opencl_device_name(device));
 printf("   File size: %u bytes\n", (unsigned int) size);
 printf("\n\n");
 if (apply_aes(buffer, size, device, mode, password_hash, key_size_bits) != -1)
  write_file(output_file_name, buffer, size);
 if (buffer)
  free(buffer);
 if (input_file_name)
  free(input_file_name);
 if (output_file_name)
  free(output_file_name);
 if (password)
  free(password);
 if (password_hash)
  free(password_hash);
 printf("\n\n----- It ends here... -----\n\n\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
mode
unsigned int

variable_types:
password
char *

variable_types:
device
unsigned int

variable_types:
buffer
unsigned char *

variable_types:
size
unsigned long

variable_types:
getpass
char *(char *prompt)


printarray

decompiled_code:
int __fastcall printarray(const char *a1, __int64 a2, __int64 a3)
{
unsigned __int64 v5; // r14
unsigned __int64 v6; // rbx
void *v7; // rdx
__int64 v8; // rsi

v5 = a2 - 1;
v6 = 0LL;
printf("%s[", a1);
if ( a2 )
{
do
{
v7 = (void *)("Usage: %s <cpu|gpu>\n\n" + 21);
v8 = *(_QWORD *)(a3 + 8 * v6);
if ( v5 > v6 )
v7 = &unk_402004;
++v6;
printf("%lu%s", v8, v7);
}
while ( a2 != v6 );
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, __int64 a2, __int64 a3)
{
unsigned __int64 v5; // r14
unsigned __int64 v6; // rbx
void *v7; // rdx
__int64 v8; // rsi

v5 = a2 - 1;
v6 = 0LL;
printf("%s[", a1);
if ( a2 )
{
do
{
v7 = (void *)("Usage: %s <cpu|gpu>\n\n" + 21);
v8 = *(_QWORD *)(a3 + 8 * v6);
if ( v5 > v6 )
v7 = &unk_402004;
++v6;
printf("%lu%s", v8, v7);
}
while ( a2 != v6 );
}
return puts("]");
}

original_code:
void printarray(char *msg, size_t size, size_t array[size])
{
 printf("%s[", msg);
 for (size_t i = 0; i < size; ++i)
  printf("%lu%s", (long unsigned)array[i], i < size -1 ? ", " : "");
 printf("]\n");
}

canonical_original_code:
void printarray(char *msg, unsigned long size, unsigned long array[-1])
{
 printf("%s[", msg);
 for (unsigned long i = 0; i < size; ++i)
  printf("%lu%s", (unsigned long)array[i], i < size -1 ? ", " : "");
 printf("]\n");
}

variable_types:
msg
char *

variable_types:
array
unsigned long [-1]

variable_types:
i
unsigned long


printfreq

decompiled_code:
int __fastcall printfreq(const char *a1, unsigned __int64 a2)
{
double v2; // xmm0_8

printf("%s", a1);
if ( a2 <= 0x3E7 )
return printf("%lu MHz\n", a2);
if ( (a2 & 0x8000000000000000LL) != 0LL )
v2 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v2 = (double)(int)a2;
return printf("%.2f GHz\n", v2 / 1000.0);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, unsigned __int64 a2)
{
double v2; // xmm0_8

printf("%s", a1);
if ( a2 <= 0x3E7 )
return printf("%lu MHz\n", a2);
if ( (a2 & 0x8000000000000000LL) != 0LL )
v2 = (double)(int)(a2 & 1 | (a2 >> 1)) + (double)(int)(a2 & 1 | (a2 >> 1));
else
v2 = (double)(int)a2;
return printf("%.2f GHz\n", v2 / 1000.0);
}

original_code:
void printfreq(char *msg, cl_ulong freq)
{
 printf("%s", msg);
 if (freq >= 1000)
  printf("%.2f GHz\n", (unsigned long)freq / 1000.0);
 else
  printf("%lu MHz\n", (unsigned long)freq);
}

canonical_original_code:
void printfreq(char *msg, unsigned long freq)
{
 printf("%s", msg);
 if (freq >= 1000)
  printf("%.2f GHz\n", (unsigned long)freq / 1000.0);
 else
  printf("%lu MHz\n", (unsigned long)freq);
}

variable_types:
freq
unsigned long


printsize

decompiled_code:
int __fastcall printsize(const char *a1, unsigned __int64 a2)
{
int result; // eax

printf("%s", a1);
if ( a2 <= 0x3FF )
return printf("%lu\n", a2);
if ( a2 <= 0xFFFFF )
{
printf("%lu Kb", a2 >> 10);
result = printf(" (%lu)\n", a2);
}
else
{
if ( a2 > 0x3FFFFFFF )
printf("%lu Gb", a2 >> 30);
else
printf("%lu Mb", a2 >> 20);
result = printf(" (%lu)\n", a2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, unsigned __int64 a2)
{
int result; // eax

printf("%s", a1);
if ( a2 <= 0x3FF )
return printf("%lu\n", a2);
if ( a2 <= 0xFFFFF )
{
printf("%lu Kb", a2 >> 10);
result = printf(" (%lu)\n", a2);
}
else
{
if ( a2 > 0x3FFFFFFF )
printf("%lu Gb", a2 >> 30);
else
printf("%lu Mb", a2 >> 20);
result = printf(" (%lu)\n", a2);
}
return result;
}

original_code:
void printsize(char *msg, cl_ulong size)
{
 printf("%s", msg);
 if (size < 1024)
  printf("%lu\n", (unsigned long)size);
 else if (size < 1024 * 1024)
  printf("%lu Kb", (unsigned long)size / 1024);
 else if (size < 1024 * 1024 * 1024)
  printf("%lu Mb", (unsigned long)size / 1024 / 1024);
 else
  printf("%lu Gb", (unsigned long)size / 1024 / 1024 / 1024);
 if (size >= 1024)
  printf(" (%lu)\n", (unsigned long) size);
}

canonical_original_code:
void printsize(char *msg, unsigned long size)
{
 printf("%s", msg);
 if (size < 1024)
  printf("%lu\n", (unsigned long)size);
 else if (size < 1024 * 1024)
  printf("%lu Kb", (unsigned long)size / 1024);
 else if (size < 1024 * 1024 * 1024)
  printf("%lu Mb", (unsigned long)size / 1024 / 1024);
 else
  printf("%lu Gb", (unsigned long)size / 1024 / 1024 / 1024);
 if (size >= 1024)
  printf(" (%lu)\n", (unsigned long) size);
}


decompiled_code:
void __fastcall __noreturn show_help(const char **a1)
{
const char *v1; // rax

printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", *a1);
puts(" -i INPUT the input file");
puts(" -o OUTPUT the output file");
puts(" -m MODE MODE can be encrypt or decrypt");
printf(" -k KEY_SIZE the key size can be 128, 192 or 256 (default is %d)\n", 128LL);
puts(" -p PASSWD the password; if unspecified the user will be asked to type it");
v1 = (const char *)get_opencl_device_name(0LL);
printf(" -d DEV DEV can be cpu or gpu (default is %s)\n", v1);
puts(" -g GSIZE the OpenCL global work size (default is decided by OpenCL)");
printf(" -l LSIZE the OpenCL local work size (default is %u)\n", 8LL);
putchar(10);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char **a1)
{
const char *v1; // rax

printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", *a1);
puts(" -i INPUT the input file");
puts(" -o OUTPUT the output file");
puts(" -m MODE MODE can be encrypt or decrypt");
printf(" -k KEY_SIZE the key size can be 128, 192 or 256 (default is %d)\n", 128LL);
puts(" -p PASSWD the password; if unspecified the user will be asked to type it");
v1 = (const char *)get_opencl_device_name(0LL);
printf(" -d DEV DEV can be cpu or gpu (default is %s)\n", v1);
puts(" -g GSIZE the OpenCL global work size (default is decided by OpenCL)");
printf(" -l LSIZE the OpenCL local work size (default is %u)\n", 8LL);
putchar(10);
exit(0);
}

original_code:
void show_help(char *argv[])
{
 printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", argv[0]);
 printf("  -i INPUT         the input file\n");
 printf("  -o OUTPUT        the output file\n");
 printf("  -m MODE          MODE can be encrypt or decrypt\n");
 printf("  -k KEY_SIZE      the key size can be 128, 192 or 256 (default is %d)\n", default_key_size_bits);
 printf("  -p PASSWD        the password; if unspecified the user will be asked to type it\n");
 printf("  -d DEV           DEV can be cpu or gpu (default is %s)\n", get_opencl_device_name(0));
 printf("  -g GSIZE         the OpenCL global work size (default is decided by OpenCL)\n");
 printf("  -l LSIZE         the OpenCL local work size (default is %u)\n", (unsigned) 8);
 printf("\n");
 exit(0);
}

canonical_original_code:
void show_help(char *argv[])
{
 printf("\nUsage: %s -i INPUT -o OUTPUT -m MODE [-k KEY_SIZE] [-p PASSWD] [-d DEV] [-g GSIZE] [-l LSIZE]\n\n", argv[0]);
 printf("  -i INPUT         the input file\n");
 printf("  -o OUTPUT        the output file\n");
 printf("  -m MODE          MODE can be encrypt or decrypt\n");
 printf("  -k KEY_SIZE      the key size can be 128, 192 or 256 (default is %d)\n", default_key_size_bits);
 printf("  -p PASSWD        the password; if unspecified the user will be asked to type it\n");
 printf("  -d DEV           DEV can be cpu or gpu (default is %s)\n", get_opencl_device_name(0));
 printf("  -g GSIZE         the OpenCL global work size (default is decided by OpenCL)\n");
 printf("  -l LSIZE         the OpenCL local work size (default is %u)\n", (unsigned int) 8);
 printf("\n");
 exit(0);
}


decompiled_code:
__int64 __fastcall parse_command_line(int argc, char **argv, char **a3, char **a4, _DWORD *a5, _WORD *a6, __int64 a7, __int64 a8)
{
int v12; // edx
__int64 result; // rax
size_t v14; // rax
char *v15; // rax
size_t v16; // rax
char *v17; // rax
size_t v18; // rax
char *v19; // rax

if ( argc == 1 )
LABEL_16:
show_help((const char **)argv);
*a6 = 128;
*(_QWORD *)a7 = 0LL;
*(_DWORD *)a8 = 0;
*a5 = 2;
while ( 2 )
{
v12 = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
result = (unsigned int)(v12 - 100);
switch ( v12 )
{
case 'd':
if ( !strcmp(optarg, "cpu") )
*(_DWORD *)a8 = 0;
else
*(_DWORD *)a8 = 1 - ((strcmp(optarg, "gpu") == 0) - 1);
continue;
case 'h':
goto LABEL_16;
case 'i':
v18 = strlen(optarg);
v19 = (char *)malloc(v18 + 1);
*a3 = v19;
strcpy(v19, optarg);
continue;
case 'k':
*a6 = atoi(optarg);
continue;
case 'm':
if ( !strcmp(optarg, "encrypt") )
*a5 = 0;
else
*a5 = 1 - ((strcmp(optarg, "decrypt") == 0) - 1);
continue;
case 'o':
v16 = strlen(optarg);
v17 = (char *)malloc(v16 + 1);
*a4 = v17;
strcpy(v17, optarg);
continue;
case 'p':
v14 = strlen(optarg);
v15 = (char *)malloc(v14 + 1);
*(_QWORD *)a7 = v15;
strcpy(v15, optarg);
continue;
default:
if ( v12 != -1 )
continue;
return result;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv, char **a3, char **a4, _DWORD *a5, _WORD *a6, __int64 a7, __int64 a8)
{
int v12; // edx
__int64 result; // rax
size_t v14; // rax
char *v15; // rax
size_t v16; // rax
char *v17; // rax
size_t v18; // rax
char *v19; // rax

if ( argc == 1 )
LABEL_16:
func0((const char **)argv);
*a6 = 128;
*(_QWORD *)a7 = 0LL;
*(_DWORD *)a8 = 0;
*a5 = 2;
while ( 2 )
{
v12 = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
result = (unsigned int)(v12 - 100);
switch ( v12 )
{
case 'd':
if ( !strcmp(optarg, "cpu") )
*(_DWORD *)a8 = 0;
else
*(_DWORD *)a8 = 1 - ((strcmp(optarg, "gpu") == 0) - 1);
continue;
case 'h':
goto LABEL_16;
case 'i':
v18 = strlen(optarg);
v19 = (char *)malloc(v18 + 1);
*a3 = v19;
strcpy(v19, optarg);
continue;
case 'k':
*a6 = atoi(optarg);
continue;
case 'm':
if ( !strcmp(optarg, "encrypt") )
*a5 = 0;
else
*a5 = 1 - ((strcmp(optarg, "decrypt") == 0) - 1);
continue;
case 'o':
v16 = strlen(optarg);
v17 = (char *)malloc(v16 + 1);
*a4 = v17;
strcpy(v17, optarg);
continue;
case 'p':
v14 = strlen(optarg);
v15 = (char *)malloc(v14 + 1);
*(_QWORD *)a7 = v15;
strcpy(v15, optarg);
continue;
default:
if ( v12 != -1 )
continue;
return result;
}
}
}

original_code:
void parse_command_line(int argc, char *argv[], char **input_file_name, char **output_file_name, aes_mode * mode, unsigned short *key_size_bits, char **password, opencl_device * device)
{
 if (argc == 1)
  show_help(argv);
 int c;
 *key_size_bits = default_key_size_bits;
 *password = ((void *)0);
 *device = 0;
 *mode = 2;
 do {
  c = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
  switch (c) {
  case 'i':
   *input_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*input_file_name, optarg);
   break;
  case 'o':
   *output_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*output_file_name, optarg);
   break;
  case 'd':
   if (strcmp(optarg, "cpu") == 0)
    *device = 0;
   else if (strcmp(optarg, "gpu") == 0)
    *device = 1;
   else
    *device = 2;
   break;
  case 'k':
   *key_size_bits = atoi(optarg);
   break;
  case 'p':
   *password = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*password, optarg);
   break;
  case 'm':
   if (strcmp(optarg, "encrypt") == 0)
    *mode = 0;
   else if (strcmp(optarg, "decrypt") == 0)
    *mode = 1;
   else
    *mode = 2;
   break;
  case 'h':
   show_help(argv);
  }
 } while (c != -1);
}

canonical_original_code:
void parse_command_line(int argc, char *argv[], char **input_file_name, char **output_file_name, unsigned int *mode, unsigned short *key_size_bits, char **password, unsigned int *device)
{
 if (argc == 1)
  show_help(argv);
 int c;
 *key_size_bits = default_key_size_bits;
 *password = ((void *)0);
 *device = 0;
 *mode = 2;
 do {
  c = getopt(argc, argv, "hi:o:m:k:p:d:g:l:");
  switch (c) {
  case 'i':
   *input_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*input_file_name, optarg);
   break;
  case 'o':
   *output_file_name = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*output_file_name, optarg);
   break;
  case 'd':
   if (strcmp(optarg, "cpu") == 0)
    *device = 0;
   else if (strcmp(optarg, "gpu") == 0)
    *device = 1;
   else
    *device = 2;
   break;
  case 'k':
   *key_size_bits = atoi(optarg);
   break;
  case 'p':
   *password = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
   strcpy(*password, optarg);
   break;
  case 'm':
   if (strcmp(optarg, "encrypt") == 0)
    *mode = 0;
   else if (strcmp(optarg, "decrypt") == 0)
    *mode = 1;
   else
    *mode = 2;
   break;
  case 'h':
   show_help(argv);
  }
 } while (c != -1);
}

variable_types:
mode
unsigned int *

variable_types:
password
char **

variable_types:
device
unsigned int *

variable_types: c int


decompiled_code:
__int64 __fastcall check_arguments(int a1, int a2, int a3)
{
__int64 result; // rax

if ( a1 == 2 )
{
fwrite("ERROR: wrong AES mode, it should be encrypt or decrypt.\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
result = a2 & 0xFFFFFFBF;
if ( (a2 & 0xFFBF) != 128 && (_WORD)a2 != 256 )
{
fwrite("ERROR: wrong key size, it should be 128, 192 or 256.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
if ( a3 == 2 )
{
fwrite("ERROR: wrong OpenCL device, it should be cpu or gpu.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
return result;
}

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

if ( a1 == 2 )
{
fwrite("ERROR: wrong AES mode, it should be encrypt or decrypt.\n", 1uLL, 0x38uLL, stderr);
exit(1);
}
result = a2 & 0xFFFFFFBF;
if ( (a2 & 0xFFBF) != 128 && (_WORD)a2 != 256 )
{
fwrite("ERROR: wrong key size, it should be 128, 192 or 256.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
if ( a3 == 2 )
{
fwrite("ERROR: wrong OpenCL device, it should be cpu or gpu.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
return result;
}

original_code:
void check_arguments(aes_mode mode, unsigned short key_size_bits, opencl_device device)
{
 if (mode == 2) {
  fprintf(stderr, "ERROR: wrong AES mode, it should be encrypt or decrypt.\n");
  exit(1);
 }
 if (key_size_bits != 128 && key_size_bits != 192 && key_size_bits != 256) {
  fprintf(stderr, "ERROR: wrong key size, it should be 128, 192 or 256.\n");
  exit(1);
 }
 if (device == 2) {
  fprintf(stderr, "ERROR: wrong OpenCL device, it should be cpu or gpu.\n");
  exit(1);
 }
}

canonical_original_code:
void check_arguments(unsigned int mode, unsigned short key_size_bits, unsigned int device)
{
 if (mode == 2) {
  fprintf(stderr, "ERROR: wrong AES mode, it should be encrypt or decrypt.\n");
  exit(1);
 }
 if (key_size_bits != 128 && key_size_bits != 192 && key_size_bits != 256) {
  fprintf(stderr, "ERROR: wrong key size, it should be 128, 192 or 256.\n");
  exit(1);
 }
 if (device == 2) {
  fprintf(stderr, "ERROR: wrong OpenCL device, it should be cpu or gpu.\n");
  exit(1);
 }
}


decompiled_code:
void *__fastcall hash_password(char *s, size_t n)
{
void *v2; // r12
size_t v3; // rax
const void *v4; // rax
_BYTE v6[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = malloc(n);
sha256_init(v6);
v3 = strlen(s);
sha256_write(v6, s, v3);
sha256_final(v6);
v4 = (const void *)sha256_read(v6);
return memcpy(v2, v4, n);
}

canonical_decompiled_code:
void *__fastcall func3(char *s, size_t n)
{
void *v2; // r12
size_t v3; // rax
const void *v4; // rax
_BYTE v6[136]; // [rsp+0h] [rbp-88h] BYREF

v2 = malloc(n);
sha256_init(v6);
v3 = strlen(s);
sha256_write(v6, s, v3);
sha256_final(v6);
v4 = (const void *)sha256_read(v6);
return memcpy(v2, v4, n);
}

original_code:
cl_uchar *hash_password(char *password, size_t size)
{
 cl_uchar *hash = (cl_uchar *) malloc(size * sizeof(cl_uchar));
 SHA256_CONTEXT context;
 sha256_init(&context);
 sha256_write(&context, (unsigned char *) password, strlen(password));
 sha256_final(&context);
 memcpy(hash, sha256_read(&context), size);
 return hash;
}

canonical_original_code:
unsigned char *hash_password(char *password, unsigned long size)
{
 unsigned char *hash = (cl_uchar *) malloc(size * sizeof(cl_uchar));
 struct SHA256_CONTEXT context;
 sha256_init(&context);
 sha256_write(&context, (unsigned char *) password, strlen(password));
 sha256_final(&context);
 memcpy(hash, sha256_read(&context), size);
 return hash;
}

variable_types:
hash
unsigned char *

variable_types: struct SHA256_CONTEXT { unsigned int h0; unsigned int nblocks; unsigned char buf[64]; int count; }