parseOptions

decompiled_code:
__int64 __fastcall parseOptions(int a1, char *const *a2)
{
int v2; // eax
__int64 result; // rax
unsigned __int64 i; // r12
const char *v5; // rdx

while ( 1 )
{
v2 = getopt(a1, a2, "i:hv");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'i':
gIdleTimeout = atoi(optarg);
break;
case 'v':
gVerbose = 1;
break;
case 'h':
gDisplayHelp = 1;
break;
default:
goto LABEL_5;
}
}
result = 1LL;
if ( optind != a1 )
{
fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", *(const char **)a2);
for ( i = optind; i < a1; ++i )
{
v5 = a2[i];
fprintf(stderr, " '%s'", v5);
}
fputc(10, stderr);
LABEL_5:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char *const *a2)
{
int v2; // eax
__int64 result; // rax
unsigned __int64 i; // r12
const char *v5; // rdx

while ( 1 )
{
v2 = getopt(a1, a2, "i:hv");
if ( v2 == -1 )
break;
switch ( v2 )
{
case 'i':
gIdleTimeout = atoi(optarg);
break;
case 'v':
gVerbose = 1;
break;
case 'h':
gDisplayHelp = 1;
break;
default:
goto LABEL_5;
}
}
result = 1LL;
if ( optind != a1 )
{
fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", *(const char **)a2);
for ( i = optind; i < a1; ++i )
{
v5 = a2[i];
fprintf(stderr, " '%s'", v5);
}
fputc(10, stderr);
LABEL_5:
result = 0LL;
}
return result;
}

original_code:
static int parseOptions(int argc, char *argv[]) {
    int option = 0;
    while ((option = getopt(argc, argv, "i:hv")) != -1) {
        switch (option) {
            case 'i': gIdleTimeout = atoi(optarg); break;
            case 'h': gDisplayHelp = 1; break;
            case 'v': gVerbose = 1; break;
            default: return 0;
        }
    }
    if (optind == argc) {
        return 1;
    }
    else {
        fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", argv[0]);
        for (size_t i = optind; i < argc; ++i) {
            fprintf(stderr, " '%s'", argv[i]);
        }
        fprintf(stderr, "\n");
        return 0;
    }
}

canonical_original_code:
static int parseOptions(int argc, char *argv[]) {
    int option = 0;
    while ((option = getopt(argc, argv, "i:hv")) != -1) {
        switch (option) {
            case 'i': gIdleTimeout = atoi(optarg); break;
            case 'h': gDisplayHelp = 1; break;
            case 'v': gVerbose = 1; break;
            default: return 0;
        }
    }
    if (optind == argc) {
        return 1;
    }
    else {
        fprintf(stderr, "%s: wrong number of arguments -- expected none, found:", argv[0]);
        for (unsigned long i = optind; i < argc; ++i) {
            fprintf(stderr, " '%s'", argv[i]);
        }
        fprintf(stderr, "\n");
        return 0;
    }
}

variable_types: option int

variable_types:
i
unsigned long


setupSignals

repo: aktau/hhpc

decompiled_code:
__int64 setupSignals()
{
int v0; // er8
__int64 result; // rax
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

v2.sa_handler = (__sighandler_t)signalHandler;
memset(&v2.sa_mask, 0, 0x90uLL);
sigemptyset(&v2.sa_mask);
if ( sigaction(15, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGTERM");
result = 0LL;
}
else if ( sigaction(1, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGHUP");
result = 0LL;
}
else if ( sigaction(2, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGINT");
result = 0LL;
}
else
{
v0 = sigaction(3, &v2, 0LL);
result = 1LL;
if ( v0 == -1 )
{
perror("hhpc: could not register SIGQUIT");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // er8
__int64 result; // rax
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

v2.sa_handler = (__sighandler_t)signalHandler;
memset(&v2.sa_mask, 0, 0x90uLL);
sigemptyset(&v2.sa_mask);
if ( sigaction(15, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGTERM");
result = 0LL;
}
else if ( sigaction(1, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGHUP");
result = 0LL;
}
else if ( sigaction(2, &v2, 0LL) == -1 )
{
perror("hhpc: could not register SIGINT");
result = 0LL;
}
else
{
v0 = sigaction(3, &v2, 0LL);
result = 1LL;
if ( v0 == -1 )
{
perror("hhpc: could not register SIGQUIT");
result = 0LL;
}
}
return result;
}

original_code:
static int setupSignals() {
    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.__sigaction_handler.sa_handler = signalHandler;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    if (sigaction(15, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGTERM");
        return 0;
    }
    if (sigaction(1, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGHUP");
        return 0;
    }
    if (sigaction(2, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGINT");
        return 0;
    }
    if (sigaction(3, &act, ((void *)0)) == -1) {
        perror("hhpc: could not register SIGQUIT");
        return 0;
    }
    return 1;
}

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

return_type: int

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

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


delay

decompiled_code:
void __fastcall delay(__time_t a1, __int64 a2)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1;
v2.tv_nsec = 1000000 * a2;
if ( nanosleep(&v2, 0LL) == -1 )
signalHandler();
}

canonical_decompiled_code:
void __fastcall func4(__time_t a1, __int64 a2)
{
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1;
v2.tv_nsec = 1000000 * a2;
if ( nanosleep(&v2, 0LL) == -1 )
func0();
}

original_code:
static void delay(time_t sec, long msec) {
    struct timespec sleep;
    sleep.tv_sec = sec;
    sleep.tv_nsec = (msec % 1000) * 1000 * 1000;
    if (nanosleep(&sleep, ((void *)0)) == -1) {
        signalHandler(0);
    }
}

canonical_original_code:
static void delay(long sec, long msec) {
    struct timespec sleep;
    sleep.tv_sec = sec;
    sleep.tv_nsec = (msec % 1000) * 1000 * 1000;
    if (nanosleep(&sleep, ((void *)0)) == -1) {
        signalHandler(0);
    }
}

variable_types: sec long

variable_types: msec long

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

return_type: void


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
int v1; // ebp
int result; // eax
const char *v3; // rdx
char **v4; // rbx
const char *v5; // rcx

v1 = maxStrlen_constprop_0();
result = printf("usage: %s [-hv] [-i seconds]\n", a1);
v3 = optionDescs_0;
if ( *optionDescs_0 )
{
v4 = &optionDescs_0;
do
{
v5 = v4[1];
v4 += 2;
result = printf(" %-*s %s\n", v1, v3, v5);
v3 = *v4;
}
while ( **v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
int v1; // ebp
int result; // eax
const char *v3; // rdx
char **v4; // rbx
const char *v5; // rcx

v1 = func5();
result = printf("usage: %s [-hv] [-i seconds]\n", a1);
v3 = optionDescs_0;
if ( *optionDescs_0 )
{
v4 = &optionDescs_0;
do
{
v5 = v4[1];
v4 += 2;
result = printf(" %-*s %s\n", v1, v3, v5);
v3 = *v4;
}
while ( **v4 );
}
return result;
}

original_code:
static void usage(char *progName) {
    static char *optionDescs[] = {
        "-i seconds", "amount of time to wait before hiding the cursor",
        "-h", "display this help message",
        "-v", "be verbose",
        ""
    };
    size_t maxLen = maxStrlen(optionDescs);
    printf("usage: %s [-hv] [-i seconds]\n", progName);
    for (size_t i = 0; *optionDescs[i] != '\0'; i += 2) {
        printf("    %-*s    %s\n", maxLen, optionDescs[i], optionDescs[i+1]);
    }
}

canonical_original_code:
static void usage(char *progName) {
    static char *optionDescs[] = {
        "-i seconds", "amount of time to wait before hiding the cursor",
        "-h", "display this help message",
        "-v", "be verbose",
        ""
    };
    unsigned long maxLen = maxStrlen(optionDescs);
    printf("usage: %s [-hv] [-i seconds]\n", progName);
    for (unsigned long i = 0; *optionDescs[i] != '\0'; i += 2) {
        printf("    %-*s    %s\n", maxLen, optionDescs[i], optionDescs[i+1]);
    }
}

variable_types:
progName
char *

variable_types:
optionDescs
char *[]

variable_types:
maxLen
unsigned long


initializeList

decompiled_code:
_QWORD *initializeList()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
List* initializeList(){
  List *list = (List*)malloc(sizeof(List));
  list->head = ((void *)0);
  return list;
}

canonical_original_code:
struct __LinkedList *initializeList(){
  struct __LinkedList *list = (List*)malloc(sizeof(List));
  list->head = ((void *)0);
  return list;
}

variable_types: struct __LinkedList { struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell { struct __Value *car; struct __Value *cdr; } *cons; }; } *head; } *

user_defined_types: struct __LinkedList { struct __Value *head; }

user_defined_types: struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell *cons; }; }


insertCell

decompiled_code:
__int64 __fastcall insertCell(__int64 *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12
_QWORD *v4; // rax
__int64 v5; // rdx

if ( !a2 )
return 0LL;
result = 0LL;
if ( a1 )
{
v3 = malloc(0x10uLL);
v4 = malloc(0x10uLL);
v5 = *a1;
*(_DWORD *)v3 = 0;
*a1 = (__int64)v3;
v3[1] = v4;
*v4 = a2;
v4[1] = v5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // r12
_QWORD *v4; // rax
__int64 v5; // rdx

if ( !a2 )
return 0LL;
result = 0LL;
if ( a1 )
{
v3 = malloc(0x10uLL);
v4 = malloc(0x10uLL);
v5 = *a1;
*(_DWORD *)v3 = 0;
*a1 = (__int64)v3;
v3[1] = v4;
*v4 = a2;
v4[1] = v5;
result = 1LL;
}
return result;
}

original_code:
int insertCell(List *list, Value *value){
  if (value==((void *)0) || list==((void *)0)){
    return 0;
  }
  Value *newValue = (Value *)malloc(sizeof(Value));
  ConsCell *newCell = (ConsCell *)malloc(sizeof(ConsCell));
  newValue->type = cellType;
  newValue->cons = newCell;
  newCell->car = value;
  newCell->cdr = list->head;
  list->head = newValue;
  return 1;
}

canonical_original_code:
int insertCell(struct __LinkedList *list, struct __Value *value){
  if (value==((void *)0) || list==((void *)0)){
    return 0;
  }
  struct __Value *newValue = (Value *)malloc(sizeof(Value));
  struct __ConsCell *newCell = (ConsCell *)malloc(sizeof(ConsCell));
  newValue->type = cellType;
  newValue->cons = newCell;
  newCell->car = value;
  newCell->cdr = list->head;
  list->head = newValue;
  return 1;
}

variable_types:
value
struct __Value *

variable_types: struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell { struct __Value *car; struct __Value *cdr; } *cons; }; } *

variable_types: struct __ConsCell { struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell *cons; }; } *car; struct __Value *cdr; } *


push

decompiled_code:
// attributes: thunk
__int64 __fastcall push(__int64 *a1, __int64 a2)
{
return insertCell(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2)
{
return func1(a1, a2);
}

original_code:
int push(List *list, Value *value){
  return insertCell(list, value);
}

canonical_original_code:
int push(struct __LinkedList *list, struct __Value *value){
  return insertCell(list, value);
}

user_defined_types: struct __ConsCell { struct __Value *car; struct __Value *cdr; }


pop

original_code:
Value* pop(List *list){
  if (!list){
    return ((void *)0);
  }
  Value *returnValue = ((void *)0);
  Value *prevHead = list->head;
  if(list->head){
    returnValue = prevHead->cons->car;
    list->head = prevHead->cons->cdr;
    free(prevHead->cons);
    free(prevHead);
  }
  return returnValue;
}

canonical_original_code:
struct __Value *pop(struct __LinkedList *list){
  if (!list){
    return ((void *)0);
  }
  struct __Value *returnValue = ((void *)0);
  struct __Value *prevHead = list->head;
  if(list->head){
    returnValue = prevHead->cons->car;
    list->head = prevHead->cons->cdr;
    free(prevHead->cons);
    free(prevHead);
  }
  return returnValue;
}

variable_types: struct __LinkedList { struct __Value *head; } *

return_type: struct __Value { int type; union { int boolValue; int intValue; double dblValue; char *stringValue; char *symbolValue; char open; char close; struct __ConsCell { struct __Value *car; struct __Value *cdr; } *cons; }; } *


destroy

decompiled_code:
void __fastcall destroy(void *ptr)
{
if ( ptr )
{
cleanup(*(void ***)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
func6(*(void ***)ptr);
free(ptr);
}
}

original_code:
void destroy(List* list){
  if (list){
    cleanup(list->head);
    free(list);
  }
}

canonical_original_code:
void destroy(struct __LinkedList *list){
  if (list){
    cleanup(list->head);
    free(list);
  }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp
_QWORD *v4; // r13
char *v5; // r12
__int64 v6; // rax
__int64 v7; // rax
_QWORD *v8; // rax
int result; // eax
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v10[0] = 0;
v4 = (_QWORD *)initializeList(argc, argv, envp);
v5 = (char *)malloc(0x100uLL);
while ( fgets(v5, 256, stdin) )
{
v6 = tokenize(v5);
v7 = append(v4, v6);
v3 = (_QWORD *)v7;
if ( v7 )
{
v8 = (_QWORD *)parse(v7, v10);
if ( v10[0] < 0 )
{
puts("syntax error. Too many close parentheses.");
return 0;
}
if ( v10[0] )
{
*v4 = *v3;
}
else if ( v8 )
{
if ( *v8 )
{
printValue();
putchar(10);
cleanup(*v4);
}
}
}
else
{
*v4 = 0LL;
}
}
if ( *v4 )
{
puts("syntax error. Too few close parentheses");
destroy(v4);
free(v3);
result = 1;
}
else
{
destroy(v4);
free(v3);
free(v5);
result = -1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
  List *tokens, *parseTree, *leftoverTokens = ((void *)0);
  leftoverTokens = initializeList();
  int depth = 0;
  char *expression = (char *)malloc(256 * sizeof(char));
  while (fgets(expression, 256, stdin)) {
     tokens = append(leftoverTokens, tokenize(expression));
     if (!tokens) {
       leftoverTokens->head = ((void *)0);
       continue;
       }
     parseTree = parse(tokens,&depth);
     if (depth < 0) {
       printf("syntax error. Too many close parentheses.\n");
       return SYNTAX_ERROR_TOO_MANY_CLOSE_PARENS;
     } else if (depth > 0) {
       leftoverTokens->head = tokens->head;
      } else {
       if (parseTree && parseTree->head){
  printValue(parseTree->head);
  printf("\n");
  cleanup(leftoverTokens->head);
       }
      }
  }
  if (leftoverTokens->head) {
    printf("syntax error. Too few close parentheses\n");
    destroy(leftoverTokens);
    free(tokens);
    return SYNTAX_ERROR_UNTERMINATED_INPUT;
  }
  destroy(leftoverTokens);
  free(tokens);
  free(expression);
  return -1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  struct __LinkedList *tokens; struct __LinkedList *parseTree; struct __LinkedList *leftoverTokens = ((void *)0);
  leftoverTokens = initializeList();
  int depth = 0;
  char *expression = (char *)malloc(256 * sizeof(char));
  while (fgets(expression, 256, stdin)) {
     tokens = append(leftoverTokens, tokenize(expression));
     if (!tokens) {
       leftoverTokens->head = ((void *)0);
       continue;
       }
     parseTree = parse(tokens,&depth);
     if (depth < 0) {
       printf("syntax error. Too many close parentheses.\n");
       return SYNTAX_ERROR_TOO_MANY_CLOSE_PARENS;
     } else if (depth > 0) {
       leftoverTokens->head = tokens->head;
      } else {
       if (parseTree && parseTree->head){
  printValue(parseTree->head);
  printf("\n");
  cleanup(leftoverTokens->head);
       }
      }
  }
  if (leftoverTokens->head) {
    printf("syntax error. Too few close parentheses\n");
    destroy(leftoverTokens);
    free(tokens);
    return SYNTAX_ERROR_UNTERMINATED_INPUT;
  }
  destroy(leftoverTokens);
  free(tokens);
  free(expression);
  return -1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: depth int

variable_types:
expression
char *


repo: alannice/learn

decompiled_code:
void __fastcall xyz_buf_destroy(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 5));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 5));
free(ptr);
}
}

original_code:
void xyz_buf_destroy(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return;
    }
    free(buf->data);
    free(buf);
    return;
}

variable_types: struct xyz_buf_t { char label[32]; int size; char *data; int len; } *


decompiled_code:
__int64 __fastcall xyz_buf_append(__int64 a1, const void *a2, int a3)
{
__int64 v5; // rdi
int v6; // ebx
__int64 v7; // rax

if ( a3 <= 0 || a2 == 0LL )
return 0xFFFFFFFFLL;
if ( !a1 )
return 0xFFFFFFFFLL;
v5 = *(int *)(a1 + 48);
if ( (int)v5 + a3 > *(_DWORD *)(a1 + 32) )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)(a1 + 40) + v5), a2, a3);
v6 = *(_DWORD *)(a1 + 48) + a3;
v7 = *(_QWORD *)(a1 + 40);
*(_DWORD *)(a1 + 48) = v6;
*(_BYTE *)(v7 + v6) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void *a2, int a3)
{
__int64 v5; // rdi
int v6; // ebx
__int64 v7; // rax

if ( a3 <= 0 || a2 == 0LL )
return 0xFFFFFFFFLL;
if ( !a1 )
return 0xFFFFFFFFLL;
v5 = *(int *)(a1 + 48);
if ( (int)v5 + a3 > *(_DWORD *)(a1 + 32) )
return 0xFFFFFFFFLL;
memcpy((void *)(*(_QWORD *)(a1 + 40) + v5), a2, a3);
v6 = *(_DWORD *)(a1 + 48) + a3;
v7 = *(_QWORD *)(a1 + 40);
*(_DWORD *)(a1 + 48) = v6;
*(_BYTE *)(v7 + v6) = 0;
return 0LL;
}

original_code:
int xyz_buf_append(struct xyz_buf_t *buf, char *data, int len)
{
    if (buf == ((void *)0) || data == ((void *)0) || len <= 0) {
        return -1;
    }
    if (buf->len + len > buf->size) {
        return -1;
    }
    memcpy(buf->data+buf->len, data, len);
    buf->len+=len;
    *(buf->data+buf->len) = '\0';
    return 0;
}

variable_types:
data
char *

variable_types: len int

user_defined_types: struct xyz_buf_t { char label[32]; int size; char *data; int len; }


original_code:
int xyz_buf_get(struct xyz_buf_t *buf, char *data, int len)
{
    if (buf == ((void *)0) || data == ((void *)0) || len <= 0) {
        return -1;
    }
    int l = buf->len >= len ? len : buf->len;
    memcpy(data, buf->data, l);
    buf->len -= l;
    if (buf->len) {
        memmove(buf->data, buf->data+l, buf->len);
    }
    *(buf->data+buf->len) = '\0';
    return l;
}

variable_types: l int


decompiled_code:
__int64 __fastcall xyz_buf_peek(__int64 a1, void *a2, signed int a3)
{
unsigned int v3; // er12

if ( a3 <= 0 || a2 == 0LL || !a1 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 48) <= a3 )
a3 = *(_DWORD *)(a1 + 48);
v3 = a3;
memcpy(a2, *(const void **)(a1 + 40), a3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, void *a2, signed int a3)
{
unsigned int v3; // er12

if ( a3 <= 0 || a2 == 0LL || !a1 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 48) <= a3 )
a3 = *(_DWORD *)(a1 + 48);
v3 = a3;
memcpy(a2, *(const void **)(a1 + 40), a3);
return v3;
}

original_code:
int xyz_buf_peek(struct xyz_buf_t *buf, char *data, int len)
{
    if (buf == ((void *)0) || data == ((void *)0) || len <= 0) {
        return -1;
    }
    int l = buf->len >= len ? len : buf->len;
    memcpy(data, buf->data, l);
    return l;
}


decompiled_code:
__int64 __fastcall xyz_buf_read(__int64 a1, int a2)
{
__int64 v4; // rsi
int v5; // edx
unsigned int v6; // er8
int v7; // eax
int v8; // eax
__int64 v9; // rdx

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
v4 = *(int *)(a1 + 48);
v5 = *(_DWORD *)(a1 + 32);
v6 = 0;
if ( (_DWORD)v4 == v5 )
return v6;
v7 = read(a2, (void *)(*(_QWORD *)(a1 + 40) + v4), v5 - (int)v4);
v6 = v7;
if ( v7 >= 0 )
{
if ( v7 )
{
v8 = *(_DWORD *)(a1 + 48) + v7;
v9 = *(_QWORD *)(a1 + 40);
*(_DWORD *)(a1 + 48) = v8;
*(_BYTE *)(v9 + v8) = 0;
return v6;
}
return (unsigned int)-1;
}
return (unsigned int)-(*_errno_location() != 4);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 v4; // rsi
int v5; // edx
unsigned int v6; // er8
int v7; // eax
int v8; // eax
__int64 v9; // rdx

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
v4 = *(int *)(a1 + 48);
v5 = *(_DWORD *)(a1 + 32);
v6 = 0;
if ( (_DWORD)v4 == v5 )
return v6;
v7 = read(a2, (void *)(*(_QWORD *)(a1 + 40) + v4), v5 - (int)v4);
v6 = v7;
if ( v7 >= 0 )
{
if ( v7 )
{
v8 = *(_DWORD *)(a1 + 48) + v7;
v9 = *(_QWORD *)(a1 + 40);
*(_DWORD *)(a1 + 48) = v8;
*(_BYTE *)(v9 + v8) = 0;
return v6;
}
return (unsigned int)-1;
}
return (unsigned int)-(*_errno_location() != 4);
}

original_code:
int xyz_buf_read(struct xyz_buf_t *buf, int fd)
{
    int n;
    if (buf == ((void *)0) || fd < 0) {
        return -1;
    }
    if (buf->len == buf->size) {
        return 0;
    }
    n = read(fd, buf->data+buf->len, buf->size-buf->len);
    if (n < 0) {
        if ((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    } else if (n == 0) {
        return -1;
    }
    buf->len += n;
    *(buf->data+buf->len) = '\0';
    return n;
}

variable_types: fd int

variable_types: n int


decompiled_code:
__int64 __fastcall xyz_buf_write(__int64 a1, int a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
__int64 v5; // rdx
int v6; // eax

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
v2 = write(a2, *(const void **)(a1 + 40), *(int *)(a1 + 48));
v3 = v2;
v4 = v2;
if ( v2 >= 0 )
{
if ( v2 )
{
memmove(*(void **)(a1 + 40), (const void *)(*(_QWORD *)(a1 + 40) + v2), *(_DWORD *)(a1 + 48) - v2);
v5 = *(_QWORD *)(a1 + 40);
v6 = *(_DWORD *)(a1 + 48) - v3;
*(_DWORD *)(a1 + 48) = v6;
*(_BYTE *)(v5 + v6) = 0;
return v4;
}
return (unsigned int)-1;
}
return (unsigned int)-(*_errno_location() != 4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // eax
int v3; // ebp
unsigned int v4; // er12
__int64 v5; // rdx
int v6; // eax

if ( !a1 || a2 < 0 )
return (unsigned int)-1;
v2 = write(a2, *(const void **)(a1 + 40), *(int *)(a1 + 48));
v3 = v2;
v4 = v2;
if ( v2 >= 0 )
{
if ( v2 )
{
memmove(*(void **)(a1 + 40), (const void *)(*(_QWORD *)(a1 + 40) + v2), *(_DWORD *)(a1 + 48) - v2);
v5 = *(_QWORD *)(a1 + 40);
v6 = *(_DWORD *)(a1 + 48) - v3;
*(_DWORD *)(a1 + 48) = v6;
*(_BYTE *)(v5 + v6) = 0;
return v4;
}
return (unsigned int)-1;
}
return (unsigned int)-(*_errno_location() != 4);
}

original_code:
int xyz_buf_write(struct xyz_buf_t *buf, int fd)
{
    int n;
    if (buf == ((void *)0) || fd < 0) {
        return -1;
    }
    n = write(fd, buf->data, buf->len);
    if (n < 0) {
        if ((*__errno_location ()) == 4) {
            return 0;
        }
        return -1;
    } else if (n == 0) {
        return -1;
    }
    memmove(buf->data, buf->data+n, buf->len-n);
    buf->len -= n;
    *(buf->data+buf->len) = '\0';
    return n;
}


decompiled_code:
__int64 __fastcall xyz_buf_drop(__int64 a1, int a2)
{
__int64 result; // rax
_BYTE *v4; // rdi
__int64 v5; // rdx
int v6; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = *(unsigned int *)(a1 + 48);
v4 = *(_BYTE **)(a1 + 40);
if ( (int)result >= a2 )
{
memmove(v4, &v4[a2], (int)result - a2);
v5 = *(_QWORD *)(a1 + 40);
v6 = *(_DWORD *)(a1 + 48) - a2;
*(_DWORD *)(a1 + 48) = v6;
*(_BYTE *)(v5 + v6) = 0;
result = (unsigned int)a2;
}
else
{
*(_DWORD *)(a1 + 48) = 0;
*v4 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
__int64 result; // rax
_BYTE *v4; // rdi
__int64 v5; // rdx
int v6; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
result = *(unsigned int *)(a1 + 48);
v4 = *(_BYTE **)(a1 + 40);
if ( (int)result >= a2 )
{
memmove(v4, &v4[a2], (int)result - a2);
v5 = *(_QWORD *)(a1 + 40);
v6 = *(_DWORD *)(a1 + 48) - a2;
*(_DWORD *)(a1 + 48) = v6;
*(_BYTE *)(v5 + v6) = 0;
result = (unsigned int)a2;
}
else
{
*(_DWORD *)(a1 + 48) = 0;
*v4 = 0;
}
return result;
}

original_code:
int xyz_buf_drop(struct xyz_buf_t *buf, int len)
{
    if (buf == ((void *)0) || len == 0) {
        return -1;
    }
    if (len > buf->len) {
        int l = buf->len;
        buf->len = 0;
        *(buf->data) = '\0';
        return l;
    }
    memmove(buf->data, buf->data+len, buf->len-len);
    buf->len -= len;
    *(buf->data+buf->len) = '\0';
    return len;
}


decompiled_code:
__int64 xyz_buf_sprintf(__int64 a1, const char *a2, ...)
{
__int64 v4; // rdi
int v5; // esi
int v6; // eax
unsigned int v7; // er8
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !a1 || !a2 )
return (unsigned int)-1;
v4 = *(int *)(a1 + 48);
v5 = *(_DWORD *)(a1 + 32) - v4;
va_start(arg, a2);
v6 = vsnprintf((char *)(*(_QWORD *)(a1 + 40) + v4), v5, a2, arg);
v7 = 0;
if ( v6 > 0 )
*(_DWORD *)(a1 + 48) += v6;
return v7;
}

canonical_decompiled_code:
__int64 func7(__int64 a1, const char *a2, ...)
{
__int64 v4; // rdi
int v5; // esi
int v6; // eax
unsigned int v7; // er8
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !a1 || !a2 )
return (unsigned int)-1;
v4 = *(int *)(a1 + 48);
v5 = *(_DWORD *)(a1 + 32) - v4;
va_start(arg, a2);
v6 = vsnprintf((char *)(*(_QWORD *)(a1 + 40) + v4), v5, a2, arg);
v7 = 0;
if ( v6 > 0 )
*(_DWORD *)(a1 + 48) += v6;
return v7;
}

original_code:
int xyz_buf_sprintf(struct xyz_buf_t *buf, char *fmt, ...)
{
    va_list vl;
    int rv;
    if (buf == ((void *)0) || fmt == ((void *)0)) {
        return -1;
    }
    __builtin_va_start(vl,fmt);
    rv = vsnprintf(buf->data+buf->len, buf->size-buf->len, fmt, vl);
    __builtin_va_end(vl);
    if (rv > 0) {
        buf->len+=rv;
    }
    return 0;
}

canonical_original_code:
int xyz_buf_sprintf(struct xyz_buf_t *buf, char *fmt, ...)
{
    __builtin_va_list vl;
    int rv;
    if (buf == ((void *)0) || fmt == ((void *)0)) {
        return -1;
    }
    __builtin_va_start(vl,fmt);
    rv = vsnprintf(buf->data+buf->len, buf->size-buf->len, fmt, vl);
    __builtin_va_end(vl);
    if (rv > 0) {
        buf->len+=rv;
    }
    return 0;
}

variable_types:
fmt
char *

variable_types: rv int


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

if ( a1 )
result = *(_QWORD *)(a1 + 40);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 40);
else
result = 0LL;
return result;
}

original_code:
char *xyz_buf_data(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return ((void *)0);
    }
    return buf->data;
}

return_type: char *


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

if ( a1 )
result = *(unsigned int *)(a1 + 48);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 48);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int xyz_buf_length(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return -1;
    }
    return buf->len;
}


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

if ( a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 48));
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 32) - *(_DWORD *)(a1 + 48));
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int xyz_buf_space(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return -1;
    }
    return buf->size - buf->len;
}


decompiled_code:
int __fastcall xyz_buf_stat(__int64 a1)
{
int result; // eax

if ( a1 )
{
puts("------ buf stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("size : %d\n", *(unsigned int *)(a1 + 32));
result = printf("len : %d\n", *(unsigned int *)(a1 + 48));
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int result; // eax

if ( a1 )
{
puts("------ buf stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("size : %d\n", *(unsigned int *)(a1 + 32));
result = printf("len : %d\n", *(unsigned int *)(a1 + 48));
}
return result;
}

original_code:
void xyz_buf_stat(struct xyz_buf_t *buf)
{
    if (buf == ((void *)0)) {
        return;
    }
    printf("------ buf stat ------\n");
    printf("*** %s ***\n", buf->label);
    printf("size : %d\n", buf->size);
    printf("len : %d\n", buf->len);
    return;
}


decompiled_code:
__int64 __fastcall xyz_conf_trim(_BYTE *a1)
{
unsigned __int64 v1; // rax
__int64 v2; // rsi
unsigned __int8 *v3; // rdx
_BYTE *v4; // rcx

v1 = (unsigned __int8)*a1;
if ( !(_BYTE)v1 )
return 0xFFFFFFFFLL;
v2 = 0x100002600LL;
v3 = a1;
v4 = a1;
do
{
while ( 1 )
{
++v3;
if ( (unsigned __int8)v1 <= 0x20u )
{
if ( _bittest64(&v2, v1) )
break;
}
*v4 = v1;
v1 = *v3;
++v4;
if ( !(_BYTE)v1 )
goto LABEL_7;
}
v1 = *v3;
}
while ( (_BYTE)v1 );
LABEL_7:
*v4 = 0;
return (unsigned int)-(*a1 == 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
unsigned __int64 v1; // rax
__int64 v2; // rsi
unsigned __int8 *v3; // rdx
_BYTE *v4; // rcx

v1 = (unsigned __int8)*a1;
if ( !(_BYTE)v1 )
return 0xFFFFFFFFLL;
v2 = 0x100002600LL;
v3 = a1;
v4 = a1;
do
{
while ( 1 )
{
++v3;
if ( (unsigned __int8)v1 <= 0x20u )
{
if ( _bittest64(&v2, v1) )
break;
}
*v4 = v1;
v1 = *v3;
++v4;
if ( !(_BYTE)v1 )
goto LABEL_7;
}
v1 = *v3;
}
while ( (_BYTE)v1 );
LABEL_7:
*v4 = 0;
return (unsigned int)-(*a1 == 0);
}

original_code:
static int xyz_conf_trim(char *line)
{
 char *d,*s;
 if(line == ((void *)0) || strlen(line) == 0) {
  return -1;
 }
 d = s = line;
 while(*s) {
  if(*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
   s++;
   continue;
  }
  *d = *s;
  s++;
  d++;
 }
 *(d++) = '\0';
 if(strlen(line) == 0) {
  return -1;
 }
 return 0;
}

canonical_original_code:
static int xyz_conf_trim(char *line)
{
 char *d; char *s;
 if(line == ((void *)0) || strlen(line) == 0) {
  return -1;
 }
 d = s = line;
 while(*s) {
  if(*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
   s++;
   continue;
  }
  *d = *s;
  s++;
  d++;
 }
 *(d++) = '\0';
 if(strlen(line) == 0) {
  return -1;
 }
 return 0;
}

variable_types:
line
char *

variable_types:
d
char *

variable_types:
s
char *


decompiled_code:
char *__fastcall xyz_conf_parse(char *s)
{
char *v1; // rax
char *v2; // rax
char *v3; // rbx
char *result; // rax

if ( !*s )
goto LABEL_8;
v1 = strchr(s, 35);
if ( v1 )
*v1 = 0;
v2 = strchr(s, 61);
v3 = v2;
if ( v2 && ((*v2 = 0, strlen(s) > 2) || strlen(v3 + 1) > 2) )
result = v3 + 1;
else
LABEL_8:
result = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char *v1; // rax
char *v2; // rax
char *v3; // rbx
char *result; // rax

if ( !*s )
goto LABEL_8;
v1 = strchr(s, 35);
if ( v1 )
*v1 = 0;
v2 = strchr(s, 61);
v3 = v2;
if ( v2 && ((*v2 = 0, strlen(s) > 2) || strlen(v3 + 1) > 2) )
result = v3 + 1;
else
LABEL_8:
result = 0LL;
return result;
}

original_code:
static char *xyz_conf_parse(char *line)
{
 char *p;
 if(line == ((void *)0) || strlen(line) == 0) {
  return ((void *)0);
 }
 p = strchr(line, '#');
 if(p) {
  *p = '\0';
 }
 p = strchr(line, '=');
 if(p == ((void *)0)) {
  return ((void *)0);
 }
 *p = '\0';
 if(strlen(line) < 3 && strlen(p+1) < 3) {
  return ((void *)0);
 }
 return p+1;
}

variable_types:
p
char *


decompiled_code:
void __fastcall xyz_conf_destroy(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
free(*v2);
free(v2[1]);
free(v2);
}
while ( v1 );
}
}

original_code:
void xyz_conf_destroy(struct xyz_conf_t *conf)
{
 struct xyz_conf_t *tmpconf;
    if(conf == ((void *)0)) {
        return;
    }
 while(conf) {
  tmpconf = conf;
  conf = conf->next;
  free(tmpconf->key);
  free(tmpconf->value);
  free(tmpconf);
 }
 return;
}

variable_types: struct xyz_conf_t { char *key; char *value; struct xyz_conf_t *next; } *


decompiled_code:
__int64 __fastcall xyz_conf_string(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
if ( !a2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
return *(_QWORD *)(v2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
__int64 v2; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
if ( !a2 )
return 0LL;
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return 0LL;
}
return *(_QWORD *)(v2 + 8);
}

original_code:
const char *xyz_conf_string(struct xyz_conf_t *conf, char *key)
{
    if(conf == ((void *)0) || key == ((void *)0)) {
        return ((void *)0);
    }
 while(conf) {
  if(strcmp(conf->key, key) == 0) {
   return conf->value;
  }
  conf = conf->next;
 }
 return ((void *)0);
}

variable_types:
key
char *

user_defined_types: struct xyz_conf_t { char *key; char *value; struct xyz_conf_t *next; }


decompiled_code:
int __fastcall xyz_conf_stat(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("------ conf stat ------"); v1; v1 = *(_QWORD *)(v1 + 16) )
result = printf("key: %-16s , value: %-16s\n", *(const char **)v1, *(const char **)(v1 + 8));
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

v1 = a1;
for ( result = puts("------ conf stat ------"); v1; v1 = *(_QWORD *)(v1 + 16) )
result = printf("key: %-16s , value: %-16s\n", *(const char **)v1, *(const char **)(v1 + 8));
return result;
}

original_code:
void xyz_conf_stat(struct xyz_conf_t *conf)
{
 printf("------ conf stat ------\n");
 while(conf) {
  printf("key: %-16s , value: %-16s\n", conf->key, conf->value);
  conf = conf->next;
 }
 return;
}


decompiled_code:
int __fastcall xyz_sock_noblock(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

original_code:
int xyz_sock_noblock(int sockfd)
{
 int flag;
 flag = fcntl(sockfd,3);
 return fcntl(sockfd, 4, flag|04000);
}

variable_types: sockfd int

variable_types: flag int


decompiled_code:
int __fastcall xyz_sock_closeonexec(int a1)
{
return fcntl(a1, 2, 1LL);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
return fcntl(a1, 2, 1LL);
}

original_code:
int xyz_sock_closeonexec(int sockfd)
{
 return fcntl(sockfd, 2, 1);
}


decompiled_code:
__int64 __fastcall xyz_sock_listen(const char *a1, __int16 a2, int a3)
{
struct hostent *v4; // rax
unsigned int v5; // er12
int optval; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

addr = 0LL;
if ( a1 )
{
v4 = gethostbyname(a1);
if ( !v4 )
{
v5 = -1;
perror("gethostbyname() error");
return v5;
}
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
}
*(_WORD *)addr.sa_data = _bswap_16(a2);
addr.sa_family = 2;
if ( a3 == 2 )
{
v5 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v5 = socket(2, 5, 132);
}
else
{
v5 = -1;
if ( a3 != 1 )
return v5;
v5 = socket(2, 1, 6);
}
if ( v5 == -1 )
{
perror("socket() error");
}
else
{
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( bind(v5, &addr, 0x10u) == -1 )
{
v5 = -1;
perror("bind() error");
}
else if ( listen(v5, 128) == -1 )
{
v5 = -1;
perror("listen() error");
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int16 a2, int a3)
{
struct hostent *v4; // rax
unsigned int v5; // er12
int optval; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

addr = 0LL;
if ( a1 )
{
v4 = gethostbyname(a1);
if ( !v4 )
{
v5 = -1;
perror("gethostbyname() error");
return v5;
}
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v4->h_addr_list;
}
*(_WORD *)addr.sa_data = func0(a2);
addr.sa_family = 2;
if ( a3 == 2 )
{
v5 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v5 = socket(2, 5, 132);
}
else
{
v5 = -1;
if ( a3 != 1 )
return v5;
v5 = socket(2, 1, 6);
}
if ( v5 == -1 )
{
perror("socket() error");
}
else
{
optval = 1;
setsockopt(v5, 1, 2, &optval, 4u);
if ( bind(v5, &addr, 0x10u) == -1 )
{
v5 = -1;
perror("bind() error");
}
else if ( listen(v5, 128) == -1 )
{
v5 = -1;
perror("listen() error");
}
}
return v5;
}

original_code:
int xyz_sock_listen(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 memset (&sin, 0, sizeof (sin));
 if(addr != ((void *)0)) {
  memset (&sin, 0, sizeof (sin));
  ht = gethostbyname(addr);
  if(ht == ((void *)0)) {
   perror ("gethostbyname() error");
   return -1;
  }
  sin.sin_addr.s_addr = *((in_addr_t *)(ht->h_addr_list[0]));
 } else {
  sin.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 }
    sin.sin_port = htons (port);
    sin.sin_family = 2;
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 int i=1;
 setsockopt(sockfd, 1, 2, &i, sizeof(i));
    if (bind (sockfd, (struct sockaddr *) &sin, sizeof (sin)) == -1)
    {
  perror ("bind() error");
  return -1;
    }
    if (listen (sockfd, 128) == -1)
    {
  perror ("listen() error");
  return -1;
    }
 return sockfd;
}

canonical_original_code:
int xyz_sock_listen(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 memset (&sin, 0, sizeof (sin));
 if(addr != ((void *)0)) {
  memset (&sin, 0, sizeof (sin));
  ht = gethostbyname(addr);
  if(ht == ((void *)0)) {
   perror ("gethostbyname() error");
   return -1;
  }
  sin.sin_addr.s_addr = *((unsigned int *)(ht->h_addr_list[0]));
 } else {
  sin.sin_addr.s_addr = ((unsigned int) 0x00000000);
 }
    sin.sin_port = htons (port);
    sin.sin_family = 2;
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 int i = 1;
 setsockopt(sockfd, 1, 2, &i, sizeof(i));
    if (bind (sockfd, (struct sockaddr *) &sin, sizeof (sin)) == -1)
    {
  perror ("bind() error");
  return -1;
    }
    if (listen (sockfd, 128) == -1)
    {
  perror ("listen() error");
  return -1;
    }
 return sockfd;
}

variable_types:
addr
char *

variable_types: port int

variable_types: type int

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: i int

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

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
int __fastcall xyz_sock_accept(int a1)
{
int result; // eax
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

addr_len = 16;
result = accept(a1, &addr, &addr_len);
if ( result == -1 )
{
perror("accept() error");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
int result; // eax
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

addr_len = 16;
result = accept(a1, &addr, &addr_len);
if ( result == -1 )
{
perror("accept() error");
result = -1;
}
return result;
}

original_code:
int xyz_sock_accept(int sockfd)
{
 struct sockaddr sa;
 socklen_t len;
 int conn;
 len = sizeof(sa);
 conn = accept(sockfd, &sa, &len);
 if(conn == -1) {
  perror("accept() error");
 }
 return conn;
}

canonical_original_code:
int xyz_sock_accept(int sockfd)
{
 struct sockaddr sa;
 unsigned int len;
 int conn;
 len = sizeof(sa);
 conn = accept(sockfd, &sa, &len);
 if(conn == -1) {
  perror("accept() error");
 }
 return conn;
}

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

variable_types:
len
unsigned int

variable_types: conn int


decompiled_code:
__int64 __fastcall xyz_sock_connect(char *name, __int16 a2, int a3)
{
unsigned int v3; // er12
struct hostent *v5; // rax
char **v6; // rax
socklen_t v7; // edx
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

if ( !name )
return (unsigned int)-1;
if ( a3 == 2 )
{
v3 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v3 = socket(2, 5, 132);
}
else
{
v3 = -1;
if ( a3 != 1 )
return v3;
v3 = socket(2, 1, 6);
}
if ( v3 == -1 )
{
perror("socket() error");
}
else
{
v5 = gethostbyname(name);
if ( v5 )
{
v6 = v5->h_addr_list;
v8 = 0LL;
*(_DWORD *)&v8.sa_data[2] = *(_DWORD *)*v6;
*(_WORD *)v8.sa_data = _bswap_16(a2);
v8.sa_family = 2;
if ( connect(v3, &v8, v7) == -1 )
{
v3 = -1;
perror("connect() error");
}
}
else
{
v3 = -1;
perror("gethostbyname() error");
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *name, __int16 a2, int a3)
{
unsigned int v3; // er12
struct hostent *v5; // rax
char **v6; // rax
socklen_t v7; // edx
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

if ( !name )
return (unsigned int)-1;
if ( a3 == 2 )
{
v3 = socket(2, 2, 17);
}
else if ( a3 == 3 )
{
v3 = socket(2, 5, 132);
}
else
{
v3 = -1;
if ( a3 != 1 )
return v3;
v3 = socket(2, 1, 6);
}
if ( v3 == -1 )
{
perror("socket() error");
}
else
{
v5 = gethostbyname(name);
if ( v5 )
{
v6 = v5->h_addr_list;
v8 = 0LL;
*(_DWORD *)&v8.sa_data[2] = *(_DWORD *)*v6;
*(_WORD *)v8.sa_data = func0(a2);
v8.sa_family = 2;
if ( connect(v3, &v8, v7) == -1 )
{
v3 = -1;
perror("connect() error");
}
}
else
{
v3 = -1;
perror("gethostbyname() error");
}
}
return v3;
}

original_code:
int xyz_sock_connect(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 if(addr == ((void *)0)) {
  return -1;
 }
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 ht = gethostbyname(addr);
 if(ht == ((void *)0)) {
  perror ("gethostbyname() error");
  return -1;
 }
 memset (&sin, 0, sizeof (sin));
 sin.sin_addr.s_addr = *((in_addr_t *)(ht->h_addr_list[0]));
    sin.sin_port = htons(port);
    sin.sin_family = 2;
 if(connect(sockfd, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) {
  perror ("connect() error");
  return -1;
 }
 return sockfd;
}

canonical_original_code:
int xyz_sock_connect(char *addr, int port, int type)
{
 struct sockaddr_in sin;
 int sockfd;
 struct hostent *ht;
 if(addr == ((void *)0)) {
  return -1;
 }
    switch(type) {
        case 1:
            sockfd = socket (2, SOCK_STREAM, IPPROTO_TCP);
            break;
        case 2:
            sockfd = socket (2, SOCK_DGRAM, IPPROTO_UDP);
            break;
        case 3:
            sockfd = socket (2, SOCK_SEQPACKET, IPPROTO_SCTP);
            break;
        default:
            return -1;
    }
    if(sockfd == -1) {
  perror ("socket() error");
  return -1;
    }
 ht = gethostbyname(addr);
 if(ht == ((void *)0)) {
  perror ("gethostbyname() error");
  return -1;
 }
 memset (&sin, 0, sizeof (sin));
 sin.sin_addr.s_addr = *((unsigned int *)(ht->h_addr_list[0]));
    sin.sin_port = htons(port);
    sin.sin_family = 2;
 if(connect(sockfd, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1) {
  perror ("connect() error");
  return -1;
 }
 return sockfd;
}

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


decompiled_code:
__int64 __fastcall xyz_sock_peeraddr(int a1, char *a2, int a3)
{
char *v5; // rsi
socklen_t len; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 <= 14 )
return 0xFFFFFFFFLL;
len = 16;
addr = 0LL;
if ( getpeername(a1, &addr, &len) < 0 )
return 0xFFFFFFFFLL;
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
if ( !v5 )
return 0xFFFFFFFFLL;
strncpy(a2, v5, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, char *a2, int a3)
{
char *v5; // rsi
socklen_t len; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
if ( a3 <= 14 )
return 0xFFFFFFFFLL;
len = 16;
addr = 0LL;
if ( getpeername(a1, &addr, &len) < 0 )
return 0xFFFFFFFFLL;
v5 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
if ( !v5 )
return 0xFFFFFFFFLL;
strncpy(a2, v5, a3);
return 0LL;
}

original_code:
int xyz_sock_peeraddr(int sockfd, char *addr, int len)
{
    struct sockaddr_in sa_in;
    socklen_t sa_len;
    char *paddr;
    int pport;
    if(addr == ((void *)0) || len < 15) {
        return -1;
    }
    sa_len = sizeof(struct sockaddr);
    bzero(&sa_in, sizeof(struct sockaddr_in));
    if(getpeername(sockfd, (struct sockaddr *)&sa_in, &sa_len ) < 0)
    {
        return -1;
    }
    paddr = inet_ntoa(sa_in.sin_addr);
    pport = ntohs(sa_in.sin_port);
    if(paddr == ((void *)0)) {
        return -1;
    }
    strncpy(addr, paddr, len);
    return 0;
}

canonical_original_code:
int xyz_sock_peeraddr(int sockfd, char *addr, int len)
{
    struct sockaddr_in sa_in;
    unsigned int sa_len;
    char *paddr;
    int pport;
    if(addr == ((void *)0) || len < 15) {
        return -1;
    }
    sa_len = sizeof(struct sockaddr);
    bzero(&sa_in, sizeof(struct sockaddr_in));
    if(getpeername(sockfd, (struct sockaddr *)&sa_in, &sa_len ) < 0)
    {
        return -1;
    }
    paddr = inet_ntoa(sa_in.sin_addr);
    pport = ntohs(sa_in.sin_port);
    if(paddr == ((void *)0)) {
        return -1;
    }
    strncpy(addr, paddr, len);
    return 0;
}

variable_types: len int

variable_types:
paddr
char *

variable_types: pport int


decompiled_code:
int __fastcall xyz_sock_read_to(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return read(fd, buf, a3);
result = select(fd + 1, &readfds, 0LL, 0LL, &v6);
switch ( result )
{
case 0:
return result;
case 1:
return read(fd, buf, a3);
case -1:
result = -(*_errno_location() != 4);
break;
default:
result = 0;
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return read(fd, buf, a3);
result = select(fd + 1, &readfds, 0LL, 0LL, &v6);
switch ( result )
{
case 0:
return result;
case 1:
return read(fd, buf, a3);
case -1:
result = -(*_errno_location() != 4);
break;
default:
result = 0;
break;
}
return result;
}

original_code:
int xyz_sock_read_to(int sockfd, char *data, int len, int usec)
{
    fd_set rdset;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rdset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return read(sockfd, data, len);
    }
    int n = select(sockfd+1, &rdset, ((void *)0), ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return read(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int xyz_sock_read_to(int sockfd, char *data, int len, int usec)
{
    struct fd_set rdset;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rdset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return read(sockfd, data, len);
    }
    int n = select(sockfd+1, &rdset, ((void *)0), ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return read(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

variable_types:
data
char *

variable_types: usec int

variable_types:
rdset
struct fd_set { long __fds_bits[-1]; }

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

variable_types: n int


decompiled_code:
int __fastcall xyz_sock_write_to(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return write(fd, buf, a3);
result = select(fd + 1, 0LL, &writefds, 0LL, &v6);
switch ( result )
{
case 0:
return result;
case 1:
return write(fd, buf, a3);
case -1:
result = -(*_errno_location() != 4);
break;
default:
result = 0;
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd, void *buf, int a3, int a4)
{
int result; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

memset(&writefds, 0, sizeof(writefds));
writefds.fds_bits[fd / 64] |= 1LL << (fd % 64);
v6.tv_sec = a4 / 1000000;
v6.tv_usec = a4 % 1000000;
if ( fd > 1023 )
return write(fd, buf, a3);
result = select(fd + 1, 0LL, &writefds, 0LL, &v6);
switch ( result )
{
case 0:
return result;
case 1:
return write(fd, buf, a3);
case -1:
result = -(*_errno_location() != 4);
break;
default:
result = 0;
break;
}
return result;
}

original_code:
int xyz_sock_write_to(int sockfd, char *data, int len, int usec)
{
    fd_set wtset;
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&wtset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return write(sockfd, data, len);
    }
    int n = select(sockfd+1, ((void *)0), &wtset, ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return write(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int xyz_sock_write_to(int sockfd, char *data, int len, int usec)
{
    struct fd_set wtset;
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&wtset)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    struct timeval tv;
    tv.tv_sec = usec/1000000;
    tv.tv_usec = usec%1000000;
    if(sockfd >= 1024) {
        return write(sockfd, data, len);
    }
    int n = select(sockfd+1, ((void *)0), &wtset, ((void *)0), &tv);
    if(n == 0) {
        return 0;
    }
    if(n == 1) {
        return write(sockfd, data, len);
    }
    if(n == -1) {
        if((*__errno_location ()) == 4) {
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
}

variable_types: sockfd int

variable_types:
wtset
struct fd_set { long __fds_bits[-1]; }

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


decompiled_code:
__int64 __fastcall xyz_domain_listen(char *name)
{
int v2; // eax
unsigned int v3; // er12
const char *v5; // rdi
int v6; // edi
struct sockaddr v7[8]; // [rsp+0h] [rbp-88h] BYREF

v2 = socket(1, 1, 6);
if ( v2 < 0 )
{
v3 = -1;
perror("socket() error");
return v3;
}
v3 = v2;
strncpy(v7[0].sa_data, name, 0x6BuLL);
if ( bind(v3, v7, 0x6Eu) == -1 )
{
v5 = "bind() error";
LABEL_8:
perror(v5);
v6 = v3;
v3 = -1;
close(v6);
unlink(name);
return v3;
}
if ( listen(v3, 1) == -1 )
{
v5 = "listen() error";
goto LABEL_8;
}
unlink(name);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *name)
{
int v2; // eax
unsigned int v3; // er12
const char *v5; // rdi
int v6; // edi
struct sockaddr v7[8]; // [rsp+0h] [rbp-88h] BYREF

v2 = socket(1, 1, 6);
if ( v2 < 0 )
{
v3 = -1;
perror("socket() error");
return v3;
}
v3 = v2;
strncpy(v7[0].sa_data, name, 0x6BuLL);
if ( bind(v3, v7, 0x6Eu) == -1 )
{
v5 = "bind() error";
LABEL_8:
perror(v5);
v6 = v3;
v3 = -1;
close(v6);
unlink(name);
return v3;
}
if ( listen(v3, 1) == -1 )
{
v5 = "listen() error";
goto LABEL_8;
}
unlink(name);
return v3;
}

original_code:
int xyz_domain_listen(char *addr)
{
    int listen_fd;
    int ret;
    struct sockaddr_un srv_addr;
    listen_fd=socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(listen_fd < 0) {
        perror("socket() error");
        return -1;
    }
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=bind(listen_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        perror("bind() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    ret=listen(listen_fd,1);
    if(ret == -1) {
        perror("listen() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    unlink(addr);
    return listen_fd;
}

canonical_original_code:
int xyz_domain_listen(char *addr)
{
    int listen_fd;
    int ret;
    struct sockaddr_un srv_addr;
    listen_fd=socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(listen_fd < 0) {
        perror("socket() error");
        return -1;
    }
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=bind(listen_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        perror("bind() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    ret=listen(listen_fd,1);
    if(ret == -1) {
        perror("listen() error");
        close(listen_fd);
        unlink(addr);
        return -1;
    }
    unlink(addr);
    return listen_fd;
}

variable_types:
addr
char *

variable_types: ret int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall xyz_domain_connect(char *src)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi
struct sockaddr v5[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 6);
if ( v1 < 0 )
{
v2 = -1;
perror("socket() error");
}
else
{
v2 = v1;
v5[0].sa_family = 1;
strncpy(v5[0].sa_data, src, 0x6BuLL);
if ( connect(v2, v5, 0x6Eu) == -1 )
{
printf("connect() error");
v4 = v2;
v2 = -1;
close(v4);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *src)
{
int v1; // eax
unsigned int v2; // er12
int v4; // edi
struct sockaddr v5[8]; // [rsp+0h] [rbp-88h] BYREF

v1 = socket(1, 1, 6);
if ( v1 < 0 )
{
v2 = -1;
perror("socket() error");
}
else
{
v2 = v1;
v5[0].sa_family = 1;
strncpy(v5[0].sa_data, src, 0x6BuLL);
if ( connect(v2, v5, 0x6Eu) == -1 )
{
printf("connect() error");
v4 = v2;
v2 = -1;
close(v4);
}
}
return v2;
}

original_code:
int xyz_domain_connect(char *addr)
{
    int connect_fd;
    struct sockaddr_un srv_addr;
    int ret;
    connect_fd = socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(connect_fd < 0)
    {
        perror("socket() error");
        return -1;
    }
    srv_addr.sun_family=1;
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=connect(connect_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        printf("connect() error");
        close(connect_fd);
        return -1;
    }
    return connect_fd;
}

canonical_original_code:
int xyz_domain_connect(char *addr)
{
    int connect_fd;
    struct sockaddr_un srv_addr;
    int ret;
    connect_fd = socket(1, SOCK_STREAM, IPPROTO_TCP);
    if(connect_fd < 0)
    {
        perror("socket() error");
        return -1;
    }
    srv_addr.sun_family=1;
    strncpy(srv_addr.sun_path, addr, sizeof(srv_addr.sun_path)-1);
    ret=connect(connect_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
    if(ret == -1)
    {
        printf("connect() error");
        close(connect_fd);
        return -1;
    }
    return connect_fd;
}

user_defined_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
__int64 __fastcall xyz_sock_sendfile(int out_fd, char *file)
{
int v2; // eax
int v3; // ebp
__off_t v4; // rbx
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

if ( stat(file, &v6) != -1 )
{
v2 = open(file, 0);
v3 = v2;
if ( v2 != -1 )
{
v4 = v6.st_size;
if ( v4 == sendfile(out_fd, v2, 0LL, v6.st_size) )
{
close(v3);
return 0LL;
}
close(v3);
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int out_fd, char *file)
{
int v2; // eax
int v3; // ebp
__off_t v4; // rbx
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

if ( stat(file, &v6) != -1 )
{
v2 = open(file, 0);
v3 = v2;
if ( v2 != -1 )
{
v4 = v6.st_size;
if ( v4 == sendfile(out_fd, v2, 0LL, v6.st_size) )
{
close(v3);
return 0LL;
}
close(v3);
}
}
return 0xFFFFFFFFLL;
}

original_code:
int xyz_sock_sendfile(int sockfd, char *file)
{
    int fd;
    struct stat statbuf;
    if(stat(file, &statbuf) == -1) {
        return -1;
    }
    fd = open(file, 00);
    if(fd == -1) {
        return -1;
    }
    if(statbuf.st_size != sendfile(sockfd, fd, 0, statbuf.st_size)) {
        close(fd);
        return -1;
    }
    close(fd);
    return 0;
}

variable_types:
file
char *

variable_types: fd int

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

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


decompiled_code:
__int64 __fastcall xyz_plugin_init(const char *a1, const char *a2)
{
char *v2; // rax
__int64 v3; // r12
char *v4; // rdi

v2 = (char *)malloc(0xB0uLL);
v3 = (__int64)v2;
if ( v2 )
{
if ( a1 )
{
snprintf(v2, 0x1FuLL, "%s", a1);
v4 = (char *)(v3 + 36);
if ( a2 )
{
LABEL_4:
snprintf(v4, 0x7FuLL, "%s", a2);
LABEL_5:
*(_QWORD *)(v3 + 168) = 0LL;
xyz_plugin_scan_constprop_0_isra_0(v3);
return v3;
}
}
else
{
*(_DWORD *)v2 = 1701736270;
v4 = v2 + 36;
v2[4] = 0;
if ( a2 )
goto LABEL_4;
}
*(_QWORD *)(v3 + 36) = 0x6E6967756C702F2ELL;
v4[8] = 0;
goto LABEL_5;
}
return v3;
}

original_code:
struct xyz_plugin_t *xyz_plugin_init(char *label, char *path)
{
    struct xyz_plugin_t *plugin;
    plugin = malloc(sizeof(struct xyz_plugin_t));
    if(plugin == ((void *)0)) {
        return ((void *)0);
    }
    if(label) {
        snprintf(plugin->label, sizeof(plugin->label)-1, "%s", label);
    } else {
        snprintf(plugin->label, sizeof(plugin->label)-1, "%s", "None");
    }
    if(path) {
        snprintf(plugin->path, sizeof(plugin->path)-1, "%s", path);
    } else {
        snprintf(plugin->path, sizeof(plugin->path)-1, "%s", "./plugin");
    }
    plugin->list = ((void *)0);
    xyz_plugin_scan(plugin);
    return plugin;
}

variable_types:
label
char *

variable_types:
path
char *

variable_types: struct xyz_plugin_t { char label[32]; int state; char path[128]; struct xyz_plugin_node_t { char name[32]; int state; void *handle; int (*plugin_init)(); int (*plugin_proc)(void *data, void *args); int (*plugin_destroy)(); struct xyz_plugin_node_t *next; } *list; } *

user_defined_types: struct xyz_plugin_t { char label[32]; int state; char path[128]; struct xyz_plugin_node_t *list; }


original_code:
int xyz_plugin_proc(struct xyz_plugin_t *plugin, void *data, void *args)
{
    int retval = 0;
    if(plugin == ((void *)0)) {
        return 0;
    }
    struct xyz_plugin_node_t *tmp = plugin->list;
    while(tmp) {
        retval = tmp->plugin_proc(data, args);
        switch(retval) {
            case (-5):
            case (-6):
                return -1;
            case (-3):
            case (-7):
                return 0;
            default:
                break;
        }
        tmp = tmp->next;
    }
    return 0;
}

variable_types:
data
void *

variable_types:
args
void *

variable_types: retval int

variable_types: struct xyz_plugin_node_t { char name[32]; int state; void *handle; int (*plugin_init)(); int (*plugin_proc)(void *data, void *args); int (*plugin_destroy)(); struct xyz_plugin_node_t *next; } *


decompiled_code:
void __fastcall xyz_plugin_destroy(void *ptr)
{
__int64 i; // rbp

if ( ptr )
{
for ( i = *((_QWORD *)ptr + 21); i; i = *((_QWORD *)ptr + 21) )
{
*((_QWORD *)ptr + 21) = *(_QWORD *)(i + 72);
(*(void (**)(void))(i + 64))();
dlclose(*(void **)(i + 40));
free((void *)i);
}
free(ptr);
}
}

original_code:
void xyz_plugin_destroy(struct xyz_plugin_t *plugin)
{
    if(plugin == ((void *)0)) {
        return;
    }
    struct xyz_plugin_node_t *tmp;
    while(plugin->list) {
        tmp = plugin->list;
        plugin->list = plugin->list->next;
        tmp->plugin_destroy();
        dlclose(tmp->handle);
        free(tmp);
    }
    free(plugin);
    return;
}

user_defined_types: struct xyz_plugin_node_t { char name[32]; int state; void *handle; int (*plugin_init)(); int (*plugin_proc)(void *data, void *args); int (*plugin_destroy)(); struct xyz_plugin_node_t *next; }


decompiled_code:
int __fastcall xyz_plugin_state(__int64 a1)
{
int result; // eax
__int64 i; // rbx

if ( a1 )
{
puts("---xyz_plugin state---");
printf("label: %s\n", (const char *)a1);
printf("path: %s\n", (const char *)(a1 + 36));
result = printf("state: %d\n", *(unsigned int *)(a1 + 32));
for ( i = *(_QWORD *)(a1 + 168); i; i = *(_QWORD *)(i + 72) )
{
printf(" name: %s\n", (const char *)i);
printf(" state: %d\n", *(unsigned int *)(i + 32));
printf(" handle: %p\n", *(const void **)(i + 40));
printf(" plugin_init: %p\n", *(const void **)(i + 48));
printf(" plugin_proc: %p\n", *(const void **)(i + 56));
result = printf(" plugin_destroy: %p\n\n", *(const void **)(i + 64));
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax
__int64 i; // rbx

if ( a1 )
{
puts("---xyz_plugin state---");
printf("label: %s\n", (const char *)a1);
printf("path: %s\n", (const char *)(a1 + 36));
result = printf("state: %d\n", *(unsigned int *)(a1 + 32));
for ( i = *(_QWORD *)(a1 + 168); i; i = *(_QWORD *)(i + 72) )
{
printf(" name: %s\n", (const char *)i);
printf(" state: %d\n", *(unsigned int *)(i + 32));
printf(" handle: %p\n", *(const void **)(i + 40));
printf(" plugin_init: %p\n", *(const void **)(i + 48));
printf(" plugin_proc: %p\n", *(const void **)(i + 56));
result = printf(" plugin_destroy: %p\n\n", *(const void **)(i + 64));
}
}
return result;
}

original_code:
void xyz_plugin_state(struct xyz_plugin_t *plugin)
{
    if(plugin == ((void *)0)) {
        return;
    }
    printf("---xyz_plugin state---\n");
    printf("label: %s\n", plugin->label);
    printf("path: %s\n", plugin->path);
    printf("state: %d\n", plugin->state);
    if(plugin->list) {
        struct xyz_plugin_node_t *tmp = plugin->list;
        while(tmp) {
            printf("  name: %s\n", tmp->name);
            printf("  state: %d\n", tmp->state);
            printf("  handle: %p\n", tmp->handle);
            printf("  plugin_init: %p\n", tmp->plugin_init);
            printf("  plugin_proc: %p\n", tmp->plugin_proc);
            printf("  plugin_destroy: %p\n\n", tmp->plugin_destroy);
            tmp = tmp->next;
        }
    }
    return;
}


decompiled_code:
void xyz_netmodel_sigchld()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) )
--g_xyz_netmodel_num;
}

canonical_decompiled_code:
void func0()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) )
--g_xyz_netmodel_num;
}

original_code:
void xyz_netmodel_sigchld(int no)
{
    pid_t pid;
    int status;
    while((pid = waitpid(-1, &status, 1)) != 0)
        g_xyz_netmodel_num--;
    return;
}

canonical_original_code:
void xyz_netmodel_sigchld(int no)
{
    int pid;
    int status;
    while((pid = waitpid(-1, &status, 1)) != 0)
        g_xyz_netmodel_num--;
    return;
}

variable_types: no int

variable_types: pid int

variable_types: status int


decompiled_code:
void *__fastcall xyz_netmodel_perthread_func(void *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
pthread_detach(v1);
(*((void (__fastcall **)(_QWORD))a1 + 1))(*(unsigned int *)a1);
close(*(_DWORD *)a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
pthread_detach(v1);
(*((void (__fastcall **)(_QWORD))a1 + 1))(*(unsigned int *)a1);
close(*(_DWORD *)a1);
return 0LL;
}

original_code:
void *xyz_netmodel_perthread_func(void *args)
{
    struct xyz_netmodel_thread_args_t *thread_args = args;
    pthread_detach(pthread_self());
    thread_args->func(thread_args->fd);
    close(thread_args->fd);
    return ((void *)0);
}

variable_types: struct xyz_netmodel_thread_args_t { int fd; int (*func)(int fd); } *

return_type: void *


decompiled_code:
void __fastcall __noreturn xyz_netmodel_threadpool_func(void *a1)
{
pthread_t v1; // rax
unsigned int v2; // ebp

v1 = pthread_self();
pthread_detach(v1);
while ( 1 )
{
pthread_mutex_lock(&xyz_netmodel_mutex);
pthread_cond_wait(&xyz_netmodel_cond, &xyz_netmodel_mutex);
v2 = xyz_netmodel_connfd;
pthread_mutex_unlock(&xyz_netmodel_mutex);
(*((void (__fastcall **)(_QWORD))a1 + 1))(v2);
close(v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
pthread_t v1; // rax
unsigned int v2; // ebp

v1 = pthread_self();
pthread_detach(v1);
while ( 1 )
{
pthread_mutex_lock(&xyz_netmodel_mutex);
pthread_cond_wait(&xyz_netmodel_cond, &xyz_netmodel_mutex);
v2 = xyz_netmodel_connfd;
pthread_mutex_unlock(&xyz_netmodel_mutex);
(*((void (__fastcall **)(_QWORD))a1 + 1))(v2);
close(v2);
}
}

original_code:
void *xyz_netmodel_threadpool_func(void *args)
{
    int connfd;
    struct xyz_netmodel_threadpool_t *threadpool = args;
    pthread_detach(pthread_self());
    while(1) {
        pthread_mutex_lock(&xyz_netmodel_mutex);
        pthread_cond_wait(&xyz_netmodel_cond, &xyz_netmodel_mutex);
        connfd = xyz_netmodel_connfd;
        pthread_mutex_unlock(&xyz_netmodel_mutex);
        threadpool->func(connfd);
        close(connfd);
    }
    return ((void *)0);
}

variable_types: connfd int

variable_types: struct xyz_netmodel_threadpool_t { unsigned long tid; int (*func)(int fd); } *


decompiled_code:
__int64 __fastcall xyz_netmodel_perfork(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
unsigned int v5; // ebp
__pid_t v6; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
do
{
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
if ( g_xyz_netmodel_num > a2 )
{
close(v4);
}
else
{
v6 = fork();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
if ( !v6 )
{
close(fd);
a3(v5);
close(v5);
exit(0);
}
close(v5);
++g_xyz_netmodel_num;
}
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
unsigned int v5; // ebp
__pid_t v6; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
do
{
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
if ( g_xyz_netmodel_num > a2 )
{
close(v4);
}
else
{
v6 = fork();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
if ( !v6 )
{
close(fd);
a3(v5);
close(v5);
exit(0);
}
close(v5);
++g_xyz_netmodel_num;
}
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_perfork(int listenfd, int count, xyz_netmodel_func func)
{
    int connfd;
    struct sockaddr addr;
    socklen_t addrlen;
    signal(17, xyz_netmodel_sigchld);
    while(1) {
        addrlen = sizeof(struct sockaddr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        if(g_xyz_netmodel_num > count) {
            close(connfd);
            continue;
        }
        switch(fork()) {
            case 0:
                close(listenfd);
                func(connfd);
                close(connfd);
                exit(0);
            case -1:
                return -1;
            default:
                close(connfd);
                g_xyz_netmodel_num++;
                break;
        }
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_perfork(int listenfd, int count, int (*func)(int fd))
{
    int connfd;
    struct sockaddr addr;
    unsigned int addrlen;
    signal(17, xyz_netmodel_sigchld);
    while(1) {
        addrlen = sizeof(struct sockaddr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        if(g_xyz_netmodel_num > count) {
            close(connfd);
            continue;
        }
        switch(fork()) {
            case 0:
                close(listenfd);
                func(connfd);
                close(connfd);
                exit(0);
            case -1:
                return -1;
            default:
                close(connfd);
                g_xyz_netmodel_num++;
                break;
        }
    }
    return 0;
}

variable_types: listenfd int

variable_types: count int

variable_types:
func
int (*)(int fd)

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

variable_types:
addrlen
unsigned int


decompiled_code:
__int64 xyz_netmodel_tempfd()
{
unsigned int v0; // er12
__int128 v2[2]; // [rsp+0h] [rbp-418h] BYREF
char v3; // [rsp+20h] [rbp-3F8h]

v3 = 0;
v2[0] = (__int128)_mm_load_si128((const __m128i *)&LC0);
v2[1] = (__int128)_mm_load_si128((const __m128i *)&LC1);
v0 = mkstemp((char *)v2);
if ( v0 != -1 )
unlink((const char *)v2);
return v0;
}

original_code:
int xyz_netmodel_tempfd()
{
    int lock_fd;
    char lock_file[1024];
    strcpy(lock_file, "/tmp/xyz_netmode_forkpool.XXXXXX");
    lock_fd = mkstemp(lock_file);
    if(lock_fd == -1) {
        return -1;
    }
    unlink(lock_file);
    return lock_fd;
}


decompiled_code:
__int64 __fastcall xyz_netmodel_lockfd(int fd)
{
int vars0; // [rsp+0h] [rbp+0h] BYREF
__int64 vars8; // [rsp+8h] [rbp+8h]
__int64 vars10; // [rsp+10h] [rbp+10h]

vars0 = 1;
vars8 = 0LL;
vars10 = 0LL;
do
{
if ( fcntl(fd, 7, &vars0) >= 0 )
return 0LL;
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
int vars0; // [rsp+0h] [rbp+0h] BYREF
__int64 vars8; // [rsp+8h] [rbp+8h]
__int64 vars10; // [rsp+10h] [rbp+10h]

vars0 = 1;
vars8 = 0LL;
vars10 = 0LL;
do
{
if ( fcntl(fd, 7, &vars0) >= 0 )
return 0LL;
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_lockfd(int fd)
{
    struct flock lock_it;
    lock_it.l_type = 1;
    lock_it.l_whence = 0;
    lock_it.l_start = 0;
    lock_it.l_len = 0;
    int rc;
    while((rc = fcntl(fd, 7, &lock_it)) < 0) {
        if((*__errno_location ()) == 4) {
            continue;
        } else {
            return -1;
        }
    }
    return 0;
}

variable_types: fd int

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }

variable_types: rc int


decompiled_code:
__int64 __fastcall xyz_netmodel_unlockfd(int a1)
{
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]

v2 = 2;
v3 = 0LL;
v4 = 0LL;
fcntl(a1, 7, &v2);
return 0LL;
}

original_code:
int xyz_netmodel_unlockfd(int fd)
{
    struct flock unlock_it;
    unlock_it.l_type = 2;
    unlock_it.l_whence = 0;
    unlock_it.l_start = 0;
    unlock_it.l_len = 0;
    fcntl(fd, 7, &unlock_it);
    return 0;
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


decompiled_code:
__int64 __fastcall xyz_netmodel_forkpool_child(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // er13
int *v6; // [rsp+8h] [rbp-60h]
socklen_t addr_len; // [rsp+1Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-48h] BYREF

v6 = _errno_location();
do
{
while ( 1 )
{
do
addr_len = 16;
while ( (unsigned int)xyz_netmodel_lockfd(fd) == -1 );
v4 = accept(a2, &addr, &addr_len);
xyz_netmodel_unlockfd(fd);
if ( v4 < 0 )
break;
a3((unsigned int)v4);
close(v4);
}
}
while ( *v6 == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // er13
int *v6; // [rsp+8h] [rbp-60h]
socklen_t addr_len; // [rsp+1Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-48h] BYREF

v6 = _errno_location();
do
{
while ( 1 )
{
do
addr_len = 16;
while ( (unsigned int)func5(fd) == -1 );
v4 = accept(a2, &addr, &addr_len);
func6(fd);
if ( v4 < 0 )
break;
a3((unsigned int)v4);
close(v4);
}
}
while ( *v6 == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_forkpool_child(int lock_fd, int listenfd, xyz_netmodel_func func)
{
    int ret;
    int connfd;
    struct sockaddr addr;
    socklen_t addrlen;
    while(1) {
        addrlen = sizeof(addr);
        ret = xyz_netmodel_lockfd(lock_fd);
        if(ret == -1) {
            continue;
        }
        connfd = accept(listenfd, &addr, &addrlen);
        xyz_netmodel_unlockfd(lock_fd);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        func(connfd);
        close(connfd);
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_forkpool_child(int lock_fd, int listenfd, int (*func)(int fd))
{
    int ret;
    int connfd;
    struct sockaddr addr;
    unsigned int addrlen;
    while(1) {
        addrlen = sizeof(addr);
        ret = xyz_netmodel_lockfd(lock_fd);
        if(ret == -1) {
            continue;
        }
        connfd = accept(listenfd, &addr, &addrlen);
        xyz_netmodel_unlockfd(lock_fd);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        func(connfd);
        close(connfd);
    }
    return 0;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall xyz_netmodel_forkpool(int a1, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
int v5; // ebp
int i; // eax
__pid_t v7; // eax

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
v4 = xyz_netmodel_tempfd();
if ( v4 != -1 )
{
g_xyz_netmodel_num = 0;
v5 = v4;
for ( i = 0; ; i = ++g_xyz_netmodel_num )
{
while ( a2 < i )
{
sleep(1u);
i = g_xyz_netmodel_num;
}
v7 = fork();
if ( v7 == -1 )
break;
if ( !v7 )
{
xyz_netmodel_forkpool_child(v5, a1, a3);
exit(0);
}
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
int v5; // ebp
int i; // eax
__pid_t v7; // eax

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
v4 = func4();
if ( v4 != -1 )
{
g_xyz_netmodel_num = 0;
v5 = v4;
for ( i = 0; ; i = ++g_xyz_netmodel_num )
{
while ( a2 < i )
{
sleep(1u);
i = g_xyz_netmodel_num;
}
v7 = fork();
if ( v7 == -1 )
break;
if ( !v7 )
{
func7(v5, a1, a3);
exit(0);
}
}
}
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_forkpool(int listenfd, int count, xyz_netmodel_func func)
{
    signal(17, xyz_netmodel_sigchld);
    int lock_fd = xyz_netmodel_tempfd();
    if(lock_fd == -1) {
        return -1;
    }
    g_xyz_netmodel_num = 0;
    while(1) {
        if(g_xyz_netmodel_num <= count) {
            switch(fork()) {
                case 0:
                    xyz_netmodel_forkpool_child(lock_fd, listenfd, func);
                    exit(0);
                case -1:
                    return -1;
                default:
                    g_xyz_netmodel_num++;
                    break;
            }
        } else {
            sleep(1);
        }
    }
    close(lock_fd);
    return 0;
}

canonical_original_code:
int xyz_netmodel_forkpool(int listenfd, int count, int (*func)(int fd))
{
    signal(17, xyz_netmodel_sigchld);
    int lock_fd = xyz_netmodel_tempfd();
    if(lock_fd == -1) {
        return -1;
    }
    g_xyz_netmodel_num = 0;
    while(1) {
        if(g_xyz_netmodel_num <= count) {
            switch(fork()) {
                case 0:
                    xyz_netmodel_forkpool_child(lock_fd, listenfd, func);
                    exit(0);
                case -1:
                    return -1;
                default:
                    g_xyz_netmodel_num++;
                    break;
            }
        } else {
            sleep(1);
        }
    }
    close(lock_fd);
    return 0;
}


decompiled_code:
__int64 __fastcall xyz_netmodel_perthread(int fd, __int64 a2, __int64 a3)
{
int *v4; // r12
int v5; // eax
socklen_t addr_len; // [rsp+4h] [rbp-64h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-58h] BYREF
int arg; // [rsp+20h] [rbp-48h] BYREF
__int64 v11; // [rsp+28h] [rbp-40h]

v4 = _errno_location();
do
{
while ( 1 )
{
addr_len = 16;
v5 = accept(fd, &addr, &addr_len);
if ( v5 < 0 )
break;
arg = v5;
v11 = a3;
pthread_create(&newthread, 0LL, xyz_netmodel_perthread_func, &arg);
}
}
while ( *v4 == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, __int64 a2, __int64 a3)
{
int *v4; // r12
int v5; // eax
socklen_t addr_len; // [rsp+4h] [rbp-64h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-58h] BYREF
int arg; // [rsp+20h] [rbp-48h] BYREF
__int64 v11; // [rsp+28h] [rbp-40h]

v4 = _errno_location();
do
{
while ( 1 )
{
addr_len = 16;
v5 = accept(fd, &addr, &addr_len);
if ( v5 < 0 )
break;
arg = v5;
v11 = a3;
pthread_create(&newthread, 0LL, xyz_netmodel_perthread_func, &arg);
}
}
while ( *v4 == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_perthread(int listenfd, int count, xyz_netmodel_func func)
{
    struct sockaddr cliaddr;
    socklen_t addrlen;
    struct xyz_netmodel_thread_args_t thread_args;
    int connfd;
    pthread_t tid;
    while(1) {
        addrlen = sizeof(cliaddr);
        connfd = accept(listenfd, &cliaddr, &addrlen);
        if(connfd >= 0) {
            thread_args.fd = connfd;
            thread_args.func = func;
            pthread_create(&tid, ((void *)0), &xyz_netmodel_perthread_func, (void*)&thread_args);
        }
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_perthread(int listenfd, int count, int (*func)(int fd))
{
    struct sockaddr cliaddr;
    unsigned int addrlen;
    struct xyz_netmodel_thread_args_t thread_args;
    int connfd;
    unsigned long tid;
    while(1) {
        addrlen = sizeof(cliaddr);
        connfd = accept(listenfd, &cliaddr, &addrlen);
        if(connfd >= 0) {
            thread_args.fd = connfd;
            thread_args.func = func;
            pthread_create(&tid, ((void *)0), &xyz_netmodel_perthread_func, (void *)&thread_args);
        }
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
    }
    return 0;
}

variable_types: struct xyz_netmodel_thread_args_t { int fd; int (*func)(int fd); }

variable_types:
tid
unsigned long


decompiled_code:
__int64 __fastcall xyz_netmodel_threadpool(int fd, int a2, __int64 a3)
{
char *v5; // rax
char *v6; // rbx
char *v7; // rbp
char *v8; // rcx
pthread_t *v9; // rdi
int *v10; // rbp
int v11; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF

v5 = (char *)malloc(16LL * a2);
if ( a2 > 0 )
{
v6 = v5;
v7 = &v5[16 * a2];
do
{
*((_QWORD *)v6 + 1) = a3;
v8 = v6;
v9 = (pthread_t *)v6;
v6 += 16;
pthread_create(v9, 0LL, (void *(*)(void *))xyz_netmodel_threadpool_func, v8);
}
while ( v7 != v6 );
}
v10 = _errno_location();
do
{
while ( 1 )
{
addr_len = 16;
v11 = accept(fd, &addr, &addr_len);
if ( v11 < 0 )
break;
pthread_mutex_lock(&xyz_netmodel_mutex);
xyz_netmodel_connfd = v11;
pthread_cond_signal(&xyz_netmodel_cond);
pthread_mutex_unlock(&xyz_netmodel_mutex);
}
}
while ( *v10 == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, int a2, __int64 a3)
{
char *v5; // rax
char *v6; // rbx
char *v7; // rbp
char *v8; // rcx
pthread_t *v9; // rdi
int *v10; // rbp
int v11; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF

v5 = (char *)malloc(16LL * a2);
if ( a2 > 0 )
{
v6 = v5;
v7 = &v5[16 * a2];
do
{
*((_QWORD *)v6 + 1) = a3;
v8 = v6;
v9 = (pthread_t *)v6;
v6 += 16;
pthread_create(v9, 0LL, (void *(*)(void *))xyz_netmodel_threadpool_func, v8);
}
while ( v7 != v6 );
}
v10 = _errno_location();
do
{
while ( 1 )
{
addr_len = 16;
v11 = accept(fd, &addr, &addr_len);
if ( v11 < 0 )
break;
pthread_mutex_lock(&xyz_netmodel_mutex);
xyz_netmodel_connfd = v11;
pthread_cond_signal(&xyz_netmodel_cond);
pthread_mutex_unlock(&xyz_netmodel_mutex);
}
}
while ( *v10 == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_threadpool(int listenfd, int count, xyz_netmodel_func func)
{
    int i=0;
    int connfd;
    struct sockaddr addr;
    socklen_t addrlen;
    struct xyz_netmodel_threadpool_t *threadpool = malloc(count*sizeof(struct xyz_netmodel_threadpool_t));
    for(i=0; i<count; i++) {
        threadpool[i].func = func;
        pthread_create(&(threadpool[i].tid), ((void *)0), xyz_netmodel_threadpool_func, (void *)&threadpool[i]);
    }
    while(1) {
        addrlen = sizeof(addr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        pthread_mutex_lock(&xyz_netmodel_mutex);
        xyz_netmodel_connfd = connfd;
        pthread_cond_signal(&xyz_netmodel_cond);
        pthread_mutex_unlock(&xyz_netmodel_mutex);
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_threadpool(int listenfd, int count, int (*func)(int fd))
{
    int i = 0;
    int connfd;
    struct sockaddr addr;
    unsigned int addrlen;
    struct xyz_netmodel_threadpool_t *threadpool = malloc(count*sizeof(struct xyz_netmodel_threadpool_t));
    for(i=0; i<count; i++) {
        threadpool[i].func = func;
        pthread_create(&(threadpool[i].tid), ((void *)0), xyz_netmodel_threadpool_func, (void *)&threadpool[i]);
    }
    while(1) {
        addrlen = sizeof(addr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        pthread_mutex_lock(&xyz_netmodel_mutex);
        xyz_netmodel_connfd = connfd;
        pthread_cond_signal(&xyz_netmodel_cond);
        pthread_mutex_unlock(&xyz_netmodel_mutex);
    }
    return 0;
}

variable_types: i int

user_defined_types: struct xyz_netmodel_threadpool_t { unsigned long tid; int (*func)(int fd); }


decompiled_code:
char *__fastcall xyz_list_create(char *src)
{
char *v1; // rax
char *v2; // r12
__int64 v3; // rax
char *v5; // rdi

v1 = (char *)malloc(0x40uLL);
v2 = v1;
if ( v1 )
{
if ( !src )
BUG();
strncpy(v1, src, 0x1FuLL);
v3 = xyz_mpool_create(v2, 24LL);
*((_QWORD *)v2 + 4) = v3;
if ( v3 )
{
*((_DWORD *)v2 + 10) = 0;
*((_QWORD *)v2 + 7) = 0LL;
*((_QWORD *)v2 + 6) = 0LL;
}
else
{
v5 = v2;
v2 = 0LL;
free(v5);
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
char *v1; // rax
char *v2; // r12
__int64 v3; // rax
char *v5; // rdi

v1 = (char *)malloc(0x40uLL);
v2 = v1;
if ( v1 )
{
if ( !src )
BUG();
strncpy(v1, src, 0x1FuLL);
v3 = xyz_mpool_create(v2, 24LL);
*((_QWORD *)v2 + 4) = v3;
if ( v3 )
{
*((_DWORD *)v2 + 10) = 0;
*((_QWORD *)v2 + 7) = 0LL;
*((_QWORD *)v2 + 6) = 0LL;
}
else
{
v5 = v2;
v2 = 0LL;
free(v5);
}
}
return v2;
}

original_code:
struct xyz_list_t *xyz_list_create(char *label)
{
 struct xyz_list_t *l;
 l = malloc(sizeof(struct xyz_list_t));
 if(l == ((void *)0)) {
  return ((void *)0);
 }
 if(label != ((void *)0) || strlen(label) > 0) {
  strncpy(l->label, label, sizeof(l->label)-1);
 }
 l->mp = xyz_mpool_create(l->label, sizeof(struct xyz_list_node_t));
 if(l->mp == ((void *)0)) {
  free(l);
  return ((void *)0);
 }
 l->count = 0;
 l->head = l->tail = ((void *)0);
 return l;
}

variable_types:
label
char *

variable_types: struct xyz_list_t { char label[32]; struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; } *mp; int count; struct xyz_list_node_t { void *data; struct xyz_list_node_t *prev; } *head; } *

user_defined_types: struct xyz_list_t { char label[32]; struct xyz_mpool_t *mp; int count; struct xyz_list_node_t *head; }


original_code:
void xyz_list_clear(struct xyz_list_t *list)
{
 if(list == ((void *)0)) {
  return;
 }
 struct xyz_list_node_t *ln = list->head;
 while(list->head) {
  ln = list->head;
  list->head = list->head->next;
  xyz_mpool_free(list->mp, ln);
 }
 list->count = 0;
 list->head = list->tail = ((void *)0);
 return;
}

variable_types: struct xyz_list_node_t { void *data; struct xyz_list_node_t *prev; } *

user_defined_types: struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; }


decompiled_code:
void __fastcall xyz_list_destroy(void *ptr)
{
if ( ptr )
{
xyz_list_clear((__int64)ptr);
xyz_mpool_destroy(*((_QWORD *)ptr + 4));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
func1((__int64)ptr);
xyz_mpool_destroy(*((_QWORD *)ptr + 4));
free(ptr);
}
}

original_code:
void xyz_list_destroy(struct xyz_list_t *list)
{
 if(list == ((void *)0)) {
  return;
 }
 xyz_list_clear(list);
 xyz_mpool_destroy(list->mp);
 free(list);
 return;
}

user_defined_types: struct xyz_list_node_t { void *data; struct xyz_list_node_t *prev; }


original_code:
int xyz_list_puthead(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = xyz_mpool_malloc(list->mp);
 if(ln == ((void *)0)) {
  return -1;
 }
 ln->data = data;
 if(list->head == ((void *)0) && list->tail == ((void *)0)) {
  list->head = list->tail = ln;
  ln->prev = ln->next = ((void *)0);
 } else {
  ln->next = list->head;
  ln->prev = ((void *)0);
  list->head->prev = ln;
  list->head = ln;
 }
 list->count++;
 return 0;
}

variable_types:
data
void *


original_code:
int xyz_list_puttail(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = xyz_mpool_malloc(list->mp);
 if(ln == ((void *)0)) {
  return -1;
 }
 ln->data = data;
 if(list->head == ((void *)0) && list->tail == ((void *)0)) {
  list->head = list->tail = ln;
  ln->prev = ln->next = ((void *)0);
 } else {
  ln->prev = list->tail;
  ln->next = ((void *)0);
  list->tail->next = ln;
  list->tail = ln;
 }
 list->count++;
 return 0;
}


original_code:
void *xyz_list_gettail(struct xyz_list_t *list)
{
 if(list == ((void *)0)) {
  return ((void *)0);
 }
 if(list->head == ((void *)0) && list->tail == ((void *)0)) {
  return ((void *)0);
 }
 struct xyz_list_node_t *ln = list->tail;
 if(list->head == list->tail) {
  list->head = list->tail = ((void *)0);
 } else {
  list->tail = list->tail->prev;
  list->tail->next = ((void *)0);
 }
 list->count--;
 void *p = ln->data;
 xyz_mpool_free(list->mp, ln);
 return p;
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall xyz_list_foreach(__int64 a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, _QWORD *a4)
{
_QWORD *v4; // rbx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD **)(a1 + 48);
if ( !v4 )
return 0LL;
while ( 1 )
{
result = a2(*v4, a3);
if ( (_DWORD)result )
break;
v4 = (_QWORD *)v4[2];
if ( !v4 )
return 0LL;
}
if ( a4 )
*a4 = *v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, _QWORD *a4)
{
_QWORD *v4; // rbx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD **)(a1 + 48);
if ( !v4 )
return 0LL;
while ( 1 )
{
result = a2(*v4, a3);
if ( (_DWORD)result )
break;
v4 = (_QWORD *)v4[2];
if ( !v4 )
return 0LL;
}
if ( a4 )
*a4 = *v4;
return result;
}

original_code:
int xyz_list_foreach(struct xyz_list_t *list, xyz_list_foreach_t func, void *arg, void **data)
{
 struct xyz_list_node_t *ln;
 int ret;
 if(list == ((void *)0) || func == ((void *)0)) {
  return -1;
 }
 ln = list->head;
 while(ln) {
  ret = func(ln->data, arg);
  if(ret != 0) {
   if(data != ((void *)0)) {
    *data = ln->data;
   }
   return ret;
  }
  ln = ln->next;
 }
 return 0;
}

canonical_original_code:
int xyz_list_foreach(struct xyz_list_t *list, int (*func)(void *data, void *arg), void *arg, void **data)
{
 struct xyz_list_node_t *ln;
 int ret;
 if(list == ((void *)0) || func == ((void *)0)) {
  return -1;
 }
 ln = list->head;
 while(ln) {
  ret = func(ln->data, arg);
  if(ret != 0) {
   if(data != ((void *)0)) {
    *data = ln->data;
   }
   return ret;
  }
  ln = ln->next;
 }
 return 0;
}

variable_types:
func
int (*)(void *data, void *arg)

variable_types:
arg
void *

variable_types:
data
void **


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

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
result = *(_QWORD *)(a1 + 48);
if ( !result )
return 0LL;
while ( *(_QWORD *)result != a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
return 1LL;
}

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

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
result = *(_QWORD *)(a1 + 48);
if ( !result )
return 0LL;
while ( *(_QWORD *)result != a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int xyz_list_find(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = list->head;
 while(ln) {
  if(ln->data == data)
   return 1;
  ln = ln->next;
 }
 return 0;
}


original_code:
int xyz_list_insert(struct xyz_list_t *list, void *data, void *newdata)
{
 if(list == ((void *)0) || data == ((void *)0) || newdata == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *lntmp = list->head;
 while(lntmp) {
  if(lntmp->data == data) {
   struct xyz_list_node_t *ln = xyz_mpool_malloc(list->mp);
   if(ln == ((void *)0)) {
    return -1;
   }
   ln->data = newdata;
   ln->prev = lntmp;
   ln->next = lntmp->next;
   lntmp->next = ln;
   if(ln->next) {
    ln->next->prev = ln;
   } else {
    list->tail = ln;
   }
   list->count++;
   return 1;
  }
  lntmp = lntmp->next;
 }
 return 0;
}

variable_types:
newdata
void *


original_code:
int xyz_list_delete(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = list->head;
 while(ln) {
  if(ln->data == data) {
   if(ln == list->head) {
    list->head = list->head->next;
    if(list->head) {
     list->head->prev = ((void *)0);
    } else {
     list->tail = list->head = ((void *)0);
    }
   } else if(ln == list->tail) {
    list->tail = list->tail->prev;
    if(list->tail) {
     list->tail->next = ((void *)0);
    } else {
     list->head = list->tail = ((void *)0);
    }
   } else {
    ln->prev->next = ln->next;
    ln->next->prev = ln->prev;
   }
   xyz_mpool_free(list->mp, ln);
   list->count--;
   return 1;
  }
  ln = ln->next;
 }
 return 0;
}


decompiled_code:
int __fastcall xyz_list_stat(__int64 a1, int a2)
{
int result; // eax
const char **i; // rbx

if ( a1 )
{
puts("------list stat------");
printf("*** %s ***\n", (const char *)a1);
printf("count : %d\n", *(unsigned int *)(a1 + 40));
result = printf("head : %p , tail : %p\n", *(const void **)(a1 + 48), *(const void **)(a1 + 56));
for ( i = *(const char ***)(a1 + 48); i; i = (const char **)i[2] )
result = printf("prev : %p , next : %p , data : %p:%s\n", i[1], i[2], *i, *i);
if ( a2 )
result = xyz_mpool_stat(*(_QWORD *)(a1 + 32), 0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, int a2)
{
int result; // eax
const char **i; // rbx

if ( a1 )
{
puts("------list stat------");
printf("*** %s ***\n", (const char *)a1);
printf("count : %d\n", *(unsigned int *)(a1 + 40));
result = printf("head : %p , tail : %p\n", *(const void **)(a1 + 48), *(const void **)(a1 + 56));
for ( i = *(const char ***)(a1 + 48); i; i = (const char **)i[2] )
result = printf("prev : %p , next : %p , data : %p:%s\n", i[1], i[2], *i, *i);
if ( a2 )
result = xyz_mpool_stat(*(_QWORD *)(a1 + 32), 0LL);
}
return result;
}

original_code:
void xyz_list_stat(struct xyz_list_t *list, int ex)
{
 if(list == ((void *)0)) {
  return;
 }
 printf("------list stat------\n");
 printf("*** %s ***\n", list->label);
 printf("count : %d\n", list->count);
 printf("head : %p , tail : %p\n", list->head, list->tail);
 struct xyz_list_node_t *ln = list->head;
 while(ln) {
  printf("prev : %p , next : %p , data : %p:%s\n", ln->prev, ln->next, ln->data, (char *)ln->data);
  ln = ln->next;
 }
 if(ex) {
  xyz_mpool_stat(list->mp, 0);
 }
 return;
}

variable_types: ex int


decompiled_code:
int *xyz_event2_create()
{
int *v0; // r12
void *v1; // rax
int *v3; // rdi

v0 = (int *)malloc(0x20uLL);
if ( v0 )
{
v1 = calloc(0x10000uLL, 0x20uLL);
*((_QWORD *)v0 + 1) = v1;
if ( v1 )
{
*((_QWORD *)v0 + 3) = 0LL;
_xyz_event2_init(v0);
}
else
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
struct xyz_event2_t *xyz_event2_create()
{
    struct xyz_event2_t *event2 = malloc(sizeof(struct xyz_event2_t));
    if(event2 == ((void *)0)) {
        return ((void *)0);
    }
    event2->nodes = calloc(65535 +1, sizeof(struct xyz_event2_node_t));
    if(event2->nodes == ((void *)0)) {
        free(event2);
        return ((void *)0);
    }
    event2->call = ((void *)0);
    __xyz_event2_init(event2);
    return event2;
}

variable_types: struct xyz_event2_t { int evfd; struct xyz_event2_node_t { int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *rdarg; void *wtarg; } *nodes; int isstop; int (*call)(); } *

user_defined_types: struct xyz_event2_t { int evfd; struct xyz_event2_node_t *nodes; int isstop; int (*call)(); }