decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
__int64 v4; // rax
_QWORD *v5; // r13
__int64 v6; // rbp
__int64 v7; // rax
_QWORD *v8; // r14
__int64 v9; // rbp
__int64 v10; // rbp
__int64 v11; // r12
__int64 v12; // rdx
__int64 v13; // rbx
__int64 v14; // r12
struct _IO_FILE *v15; // rdi
int v16; // ebx
__int64 v17; // rdx
__int64 v18; // r15
const char *v20; // r8
__int64 v21; // rcx
const char *v22; // r8
__int64 v23; // rcx
__int64 v24; // [rsp+8h] [rbp-40h]

v3 = lob_new(argc, argv, envp);
lob_set(v3, "force", "1a");
e3x_init(v3);
lob_free(v3);
v4 = mesh_new();
if ( !v4 )
{
v22 = "meshA";
v23 = 48LL;
goto LABEL_20;
}
v5 = (_QWORD *)v4;
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 48LL, (unsigned int)++unit_test_pass);
v6 = e3x_generate();
if ( !v6 )
{
v22 = "secretsA";
v23 = 50LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 50LL, (unsigned int)++unit_test_pass);
v7 = lob_linked(v6);
if ( (unsigned __int8)mesh_load(v5, v6, v7) )
{
v22 = "!mesh_load(meshA, secretsA, lob_linked(secretsA))";
v23 = 51LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 51LL, (unsigned int)++unit_test_pass);
lob_free(v6);
v8 = (_QWORD *)mesh_new();
if ( !v8 )
{
v22 = "meshB";
v23 = 55LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 55LL, (unsigned int)++unit_test_pass);
v9 = mesh_generate(v8);
if ( !v9 )
{
v22 = "secretsB";
v23 = 57LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 57LL, (unsigned int)++unit_test_pass);
lob_free(v9);
v24 = net_loopback_new(v5, v8);
if ( !v24 )
{
v20 = "pair";
v21 = 61LL;
LABEL_18:
fprintf(
stderr,
"----------------------------------------------\n"
"%s:%d: test FAILED:\n"
"Failed test: %s\n"
"----------------------------------------------\n",
"net_bulk.c",
v21,
v20);
exit(1);
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 61LL, (unsigned int)++unit_test_pass);
v10 = link_get(v5, *v8);
v11 = link_get(v8, *v5);
if ( !v10 )
{
v22 = "linkAB";
v23 = 65LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 65LL, (unsigned int)++unit_test_pass);
if ( !v11 )
{
v22 = "linkBA";
v23 = 66LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 66LL, (unsigned int)++unit_test_pass);
if ( !link_resync(v10) )
{
v20 = "link_resync(linkAB)";
v21 = 68LL;
goto LABEL_18;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 68LL, (unsigned int)++unit_test_pass);
mesh_on_open(v5, "bulk", bulk_on_open);
v13 = lob_new(v5, "bulk", v12);
lob_set(v13, "type", "bulk");
v14 = (unsigned int)e3x_exchange_cid(*(_QWORD *)(v11 + 8), 0LL);
lob_set_uint(v13, "c", v14);
if ( !link_receive(v10, v13) )
{
v20 = "link_receive(linkAB, bulkBA)";
v21 = 75LL;
goto LABEL_18;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 75LL, (unsigned int)++unit_test_pass);
if ( !chan )
{
v22 = "chan";
v23 = 76LL;
goto LABEL_20;
}
v15 = stderr;
v16 = 100;
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 76LL, (unsigned int)++unit_test_pass);
do
{
v18 = lob_new(v15, "TEST %s:%d: passed %d tests\n", v17);
lob_set_uint(v18, "c", (unsigned int)v14);
if ( !link_receive(v10, v18) )
{
v20 = "link_receive(linkAB, bulk)";
v21 = 83LL;
goto LABEL_18;
}
v15 = stderr;
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 83LL, (unsigned int)++unit_test_pass);
--v16;
}
while ( v16 );
util_sys_log(7LL, "net_bulk.c", 86LL, "main", "bulked %d", (unsigned int)bulked);
if ( bulked != 101 )
{
v22 = "bulked == i+1";
v23 = 87LL;
LABEL_20:
fprintf(
stderr,
"----------------------------------------------\n"
"%s:%d: test FAILED:\n"
"Failed test: %s\n"
"----------------------------------------------\n",
"net_bulk.c",
v23,
v22);
exit(1);
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_bulk.c", 87LL, (unsigned int)++unit_test_pass);
mesh_free(v5);
mesh_free(v8);
net_loopback_free(v24);
return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct net_loopback_struct { struct mesh_struct { struct hashname_struct { unsigned char bin[32]; } *id; struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *keys; struct e3x_self_struct { struct lob_struct *keys[2]; void *locals[2]; } *self; void *on; unsigned int state; struct link_struct { struct hashname_struct *id; struct e3x_exchange_struct { struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; } *cs; struct e3x_self_struct *self; void *remote; void *ephem; unsigned int in; unsigned int cid; unsigned char token[16]; unsigned char csid; char hex[3]; } *x; struct mesh_struct *mesh; struct lob_struct *key; struct chan_struct { struct link_struct *link; struct chan_struct *next; unsigned int id; char *type; struct lob_struct *in; unsigned int tsent; unsigned int timeout; void *arg; void (*handle)(struct chan_struct *c, void *arg); enum chan_states { CHAN_ENDED=0, CHAN_OPENING=1, CHAN_OPEN=2 } state; } *chans; unsigned int state; void *send_arg; struct link_struct *(*send_cb)(struct link_struct *link, struct lob_struct *packet, void *arg); struct link_struct *next; unsigned char csid; } *links; } *a; } *

variable_types: struct link_struct { struct hashname_struct { unsigned char bin[32]; } *id; struct e3x_exchange_struct { struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; } *cs; struct e3x_self_struct { struct lob_struct *keys[2]; void *locals[2]; } *self; void *remote; void *ephem; unsigned int in; unsigned int cid; unsigned char token[16]; unsigned char csid; char hex[3]; } *x; struct mesh_struct { struct hashname_struct *id; struct lob_struct *keys; struct e3x_self_struct *self; void *on; unsigned int state; struct link_struct *links; } *mesh; struct lob_struct *key; struct chan_struct { struct link_struct *link; struct chan_struct *next; unsigned int id; char *type; struct lob_struct *in; unsigned int tsent; unsigned int timeout; void *arg; void (*handle)(struct chan_struct *c, void *arg); enum chan_states { CHAN_ENDED=0, CHAN_OPENING=1, CHAN_OPEN=2 } state; } *chans; unsigned int state; void *send_arg; struct link_struct *(*send_cb)(struct link_struct *link, struct lob_struct *packet, void *arg); struct link_struct *next; unsigned char csid; } *

variable_types: i int

user_defined_types: struct net_loopback_struct { struct mesh_struct *a; }


repo: telehash/telehash-c

decompiled_code:
bool __fastcall e3x_cipher_init(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r8
bool result; // al
__int64 v4; // rax

e3x_cipher_default = 0LL;
e3x_cipher_sets = 0LL;
v1 = cs1c_init();
*(_QWORD *)&e3x_cipher_sets = v1;
if ( v1 )
e3x_cipher_default = v1;
v2 = lob_get(a1, &unk_150);
result = 1;
if ( !v2 )
{
v4 = cs3a_init(a1);
*((_QWORD *)&e3x_cipher_sets + 1) = v4;
if ( v4 )
e3x_cipher_default = v4;
result = lob_get(a1, &unk_150) != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r8
bool result; // al
__int64 v4; // rax

e3x_cipher_default = 0LL;
e3x_cipher_sets = 0LL;
v1 = cs1c_init();
*(_QWORD *)&e3x_cipher_sets = v1;
if ( v1 )
e3x_cipher_default = v1;
v2 = lob_get(a1, &unk_150);
result = 1;
if ( !v2 )
{
v4 = cs3a_init(a1);
*((_QWORD *)&e3x_cipher_sets + 1) = v4;
if ( v4 )
e3x_cipher_default = v4;
result = lob_get(a1, &unk_150) != 0;
}
return result;
}

original_code:
uint8_t e3x_cipher_init(lob_t options)
{
  e3x_cipher_default = ((void *)0);
  memset(e3x_cipher_sets, 0, 2 * sizeof(e3x_cipher_t));
  e3x_cipher_sets[0] = cs1c_init(options);
  if(e3x_cipher_sets[0]) e3x_cipher_default = e3x_cipher_sets[0];
  if(lob_get(options, "err")) return 1;
  e3x_cipher_sets[1] = cs3a_init(options);
  if(e3x_cipher_sets[1]) e3x_cipher_default = e3x_cipher_sets[1];
  if(lob_get(options, "err")) return 1;
  return 0;
}

canonical_original_code:
unsigned char e3x_cipher_init(struct lob_struct *options)
{
  e3x_cipher_default = ((void *)0);
  memset(e3x_cipher_sets, 0, 2 * sizeof(e3x_cipher_t));
  e3x_cipher_sets[0] = cs1c_init(options);
  if(e3x_cipher_sets[0]) e3x_cipher_default = e3x_cipher_sets[0];
  if(lob_get(options, "err")) return 1;
  e3x_cipher_sets[1] = cs3a_init(options);
  if(e3x_cipher_sets[1]) e3x_cipher_default = e3x_cipher_sets[1];
  if(lob_get(options, "err")) return 1;
  return 0;
}

variable_types: struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *

return_type: unsigned char


decompiled_code:
__int64 __fastcall e3x_cipher_set(char a1, const char *a2)
{
char v2; // r13
__int128 *v3; // rbx
__int64 v4; // r12
const char *v5; // rdi
char v7[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = a1;
v7[0] = a1;
if ( !a1 )
{
if ( a2 )
{
v2 = 0;
if ( strlen(a2) == 2 )
{
util_unhex(a2, 2LL, v7);
v2 = v7[0];
}
}
}
v3 = &e3x_cipher_sets;
while ( 1 )
{
v4 = *(_QWORD *)v3;
if ( *(_QWORD *)v3 )
{
if ( *(_BYTE *)(v4 + 137) == v2 )
break;
if ( a2 )
{
v5 = *(const char **)(v4 + 144);
if ( v5 )
{
if ( strstr(v5, a2) )
break;
}
}
}
v3 = (__int128 *)((char *)v3 + 8);
if ( v3 == &e3x_cipher_sets + 1 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, const char *a2)
{
char v2; // r13
__int128 *v3; // rbx
__int64 v4; // r12
const char *v5; // rdi
char v7[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = a1;
v7[0] = a1;
if ( !a1 )
{
if ( a2 )
{
v2 = 0;
if ( strlen(a2) == 2 )
{
util_unhex(a2, 2LL, v7);
v2 = v7[0];
}
}
}
v3 = &e3x_cipher_sets;
while ( 1 )
{
v4 = *(_QWORD *)v3;
if ( *(_QWORD *)v3 )
{
if ( *(_BYTE *)(v4 + 137) == v2 )
break;
if ( a2 )
{
v5 = *(const char **)(v4 + 144);
if ( v5 )
{
if ( strstr(v5, a2) )
break;
}
}
}
v3 = (__int128 *)((char *)v3 + 8);
if ( v3 == &e3x_cipher_sets + 1 )
return 0LL;
}
return v4;
}

original_code:
e3x_cipher_t e3x_cipher_set(uint8_t csid, char *str)
{
  uint8_t i;
  if(!csid && str && strlen(str) == 2) util_unhex(str,2,&csid);
  for(i=0; i<2; i++)
  {
    if(!e3x_cipher_sets[i]) continue;
    if(e3x_cipher_sets[i]->csid == csid) return e3x_cipher_sets[i];
    if(str && e3x_cipher_sets[i]->alg && strstr(e3x_cipher_sets[i]->alg,str)) return e3x_cipher_sets[i];
  }
  return ((void *)0);
}

canonical_original_code:
struct e3x_cipher_struct *e3x_cipher_set(unsigned char csid, char *str)
{
  unsigned char i;
  if(!csid && str && strlen(str) == 2) util_unhex(str,2,&csid);
  for(i=0; i<2; i++)
  {
    if(!e3x_cipher_sets[i]) continue;
    if(e3x_cipher_sets[i]->csid == csid) return e3x_cipher_sets[i];
    if(str && e3x_cipher_sets[i]->alg && strstr(e3x_cipher_sets[i]->alg,str)) return e3x_cipher_sets[i];
  }
  return ((void *)0);
}

variable_types:
csid
unsigned char

variable_types:
str
char *

variable_types:
i
unsigned char

return_type: struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; } *

user_defined_types: struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; }


decompiled_code:
__int64 link_check()
{
__int64 v0; // rax
const char *v1; // r9

v0 = link_up();
v1 = (const char *)&unk_50;
if ( !v0 )
v1 = "down";
status = v0 != 0;
return util_sys_log(7LL, "net_loopback.c", 9LL, "link_check", "link state change to %s", v1);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
const char *v1; // r9

v0 = link_up();
v1 = (const char *)&unk_50;
if ( !v0 )
v1 = "down";
status = v0 != 0;
return util_sys_log(7LL, "net_loopback.c", 9LL, "link_check", "link state change to %s", v1);
}

original_code:
void link_check(link_t link)
{
  status = link_up(link) ? 1 : 0;
  util_sys_log(7, "net_loopback.c", 9, __func__, "link state change to %s",status?"up":"down");
}

canonical_original_code:
void link_check(struct link_struct *link)
{
  status = link_up(link) ? 1 : 0;
  util_sys_log(7, "net_loopback.c", 9, __func__, "link state change to %s",status?"up":"down");
}

return_type: void

user_defined_types: struct link_struct { struct hashname_struct *id; struct e3x_exchange_struct *x; struct mesh_struct *mesh; struct lob_struct *key; struct chan_struct *chans; unsigned int state; void *send_arg; struct link_struct *(*send_cb)(struct link_struct *link, struct lob_struct *packet, void *arg); struct link_struct *next; unsigned char csid; }

user_defined_types: struct hashname_struct { unsigned char bin[32]; }

user_defined_types: struct e3x_exchange_struct { struct e3x_cipher_struct *cs; struct e3x_self_struct *self; void *remote; void *ephem; unsigned int in; unsigned int cid; unsigned char token[16]; unsigned char csid; char hex[3]; }

user_defined_types: struct mesh_struct { struct hashname_struct *id; struct lob_struct *keys; struct e3x_self_struct *self; void *on; unsigned int state; struct link_struct *links; }

user_defined_types: struct chan_struct { struct link_struct *link; struct chan_struct *next; unsigned int id; char *type; struct lob_struct *in; unsigned int tsent; unsigned int timeout; void *arg; void (*handle)(struct chan_struct *c, void *arg); enum chan_states state; }

user_defined_types: enum chan_states { CHAN_ENDED=0, CHAN_OPENING=1, CHAN_OPEN=2 }

user_defined_types: struct e3x_self_struct { struct lob_struct *keys[2]; void *locals[2]; }

user_defined_types: struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
_QWORD *v4; // rbp
struct _IO_FILE *v5; // rdi
__int64 v6; // rdx
_QWORD *v7; // rbx
__int64 v8; // r12
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // rax
const char *v13; // r8
__int64 v14; // rcx
const char *v15; // r8
__int64 v16; // rcx

v3 = mesh_new(argc, argv, envp);
if ( !v3 )
{
v13 = "meshA";
v14 = 15LL;
goto LABEL_20;
}
v4 = (_QWORD *)v3;
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 15LL, (unsigned int)++unit_test_pass);
mesh_on_link(v4, "test", link_check);
if ( !mesh_generate(v4) )
{
v15 = "secretsA";
v16 = 18LL;
LABEL_24:
fprintf(
stderr,
"----------------------------------------------\n"
"%s:%d: test FAILED:\n"
"Failed test: %s\n"
"----------------------------------------------\n",
"net_loopback.c",
v16,
v15);
exit(1);
}
v5 = stderr;
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 18LL, (unsigned int)++unit_test_pass);
v7 = (_QWORD *)mesh_new(v5, "TEST %s:%d: passed %d tests\n", v6);
if ( !v7 )
{
v13 = "meshB";
v14 = 21LL;
LABEL_20:
fprintf(
stderr,
"----------------------------------------------\n"
"%s:%d: test FAILED:\n"
"Failed test: %s\n"
"----------------------------------------------\n",
"net_loopback.c",
v14,
v13);
exit(1);
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 21LL, (unsigned int)++unit_test_pass);
if ( !mesh_generate(v7) )
{
v15 = "secretsB";
v16 = 23LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 23LL, (unsigned int)++unit_test_pass);
if ( !net_loopback_new(v4, v7) )
{
v15 = "pair";
v16 = 26LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 26LL, (unsigned int)++unit_test_pass);
v8 = link_get(v4, *v7);
v9 = link_get(v7, *v4);
if ( !v8 )
{
v13 = "linkAB";
v14 = 30LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 30LL, (unsigned int)++unit_test_pass);
if ( !v9 )
{
v13 = "linkBA";
v14 = 31LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 31LL, (unsigned int)++unit_test_pass);
if ( !link_resync(v8) )
{
v15 = "link_resync(linkAB)";
v16 = 33LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 33LL, (unsigned int)++unit_test_pass);
if ( !link_up(v8) )
{
v15 = "link_up(linkAB)";
v16 = 34LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 34LL, (unsigned int)++unit_test_pass);
if ( !link_up(v9) )
{
v15 = "link_up(linkBA)";
v16 = 35LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 35LL, (unsigned int)++unit_test_pass);
if ( !status )
{
v13 = "status";
v14 = 36LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 36LL, (unsigned int)++unit_test_pass);
if ( !mesh_process(v4, 1LL) )
{
v15 = "mesh_process(meshA,1)";
v16 = 38LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 38LL, (unsigned int)++unit_test_pass);
v10 = hashname_char(*v7);
if ( !mesh_linked(v4, v10, 0LL) )
{
v15 = "mesh_linked(meshA, hashname_char(meshB->id),0)";
v16 = 39LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 39LL, (unsigned int)++unit_test_pass);
if ( !mesh_unlink(v8) )
{
v15 = "mesh_unlink(linkAB)";
v16 = 40LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 40LL, (unsigned int)++unit_test_pass);
if ( !mesh_process(v4, 1LL) )
{
v15 = "mesh_process(meshA,1)";
v16 = 41LL;
goto LABEL_24;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 41LL, (unsigned int)++unit_test_pass);
v11 = hashname_char(*v7);
if ( mesh_linked(v4, v11, 0LL) )
{
v13 = "!mesh_linked(meshA, hashname_char(meshB->id),0)";
v14 = 42LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 42LL, (unsigned int)++unit_test_pass);
if ( status )
{
v13 = "!status";
v14 = 43LL;
goto LABEL_20;
}
fprintf(stderr, "TEST %s:%d: passed %d tests\n", "net_loopback.c", 43LL, (unsigned int)++unit_test_pass);
return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct mesh_struct *meshA = mesh_new();
  do { if(!(meshA)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 15, "meshA"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 15, ++unit_test_pass); } } while(0);
  mesh_on_link(meshA, "test", link_check);
  struct lob_struct *secretsA = mesh_generate(meshA);
  do { if(!(secretsA)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 18, "secretsA"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 18, ++unit_test_pass); } } while(0);
  struct mesh_struct *meshB = mesh_new();
  do { if(!(meshB)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 21, "meshB"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 21, ++unit_test_pass); } } while(0);
  struct lob_struct *secretsB = mesh_generate(meshB);
  do { if(!(secretsB)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 23, "secretsB"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 23, ++unit_test_pass); } } while(0);
  struct net_loopback_struct *pair = net_loopback_new(meshA,meshB);
  do { if(!(pair)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 26, "pair"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 26, ++unit_test_pass); } } while(0);
  struct link_struct *linkAB = link_get(meshA, meshB->id);
  struct link_struct *linkBA = link_get(meshB, meshA->id);
  do { if(!(linkAB)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 30, "linkAB"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 30, ++unit_test_pass); } } while(0);
  do { if(!(linkBA)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 31, "linkBA"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 31, ++unit_test_pass); } } while(0);
  do { if(!(link_resync(linkAB))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 33, "link_resync(linkAB)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 33, ++unit_test_pass); } } while(0);
  do { if(!(link_up(linkAB))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 34, "link_up(linkAB)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 34, ++unit_test_pass); } } while(0);
  do { if(!(link_up(linkBA))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 35, "link_up(linkBA)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 35, ++unit_test_pass); } } while(0);
  do { if(!(status)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 36, "status"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 36, ++unit_test_pass); } } while(0);
  do { if(!(mesh_process(meshA,1))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 38, "mesh_process(meshA,1)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 38, ++unit_test_pass); } } while(0);
  do { if(!(mesh_linked(meshA, hashname_char(meshB->id),0))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 39, "mesh_linked(meshA, hashname_char(meshB->id),0)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 39, ++unit_test_pass); } } while(0);
  do { if(!(mesh_unlink(linkAB))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 40, "mesh_unlink(linkAB)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 40, ++unit_test_pass); } } while(0);
  do { if(!(mesh_process(meshA,1))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 41, "mesh_process(meshA,1)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 41, ++unit_test_pass); } } while(0);
  do { if(!(!mesh_linked(meshA, hashname_char(meshB->id),0))) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 42, "!mesh_linked(meshA, hashname_char(meshB->id),0)"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 42, ++unit_test_pass); } } while(0);
  do { if(!(!status)) { fprintf(stderr, "----------------------------------------------\n" "%s:%d: test FAILED:\nFailed test: %s\n" "----------------------------------------------\n", "net_loopback.c", 43, "!status"); ; exit(1); }else{ fprintf(stderr, "TEST   %s:%d: passed %d tests\n", "net_loopback.c", 43, ++unit_test_pass); } } while(0);
  return 0;
}

variable_types: struct mesh_struct { struct hashname_struct { unsigned char bin[32]; } *id; struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *keys; struct e3x_self_struct { struct lob_struct *keys[2]; void *locals[2]; } *self; void *on; unsigned int state; struct link_struct { struct hashname_struct *id; struct e3x_exchange_struct { struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; } *cs; struct e3x_self_struct *self; void *remote; void *ephem; unsigned int in; unsigned int cid; unsigned char token[16]; unsigned char csid; char hex[3]; } *x; struct mesh_struct *mesh; struct lob_struct *key; struct chan_struct { struct link_struct *link; struct chan_struct *next; unsigned int id; char *type; struct lob_struct *in; unsigned int tsent; unsigned int timeout; void *arg; void (*handle)(struct chan_struct *c, void *arg); enum chan_states { CHAN_ENDED=0, CHAN_OPENING=1, CHAN_OPEN=2 } state; } *chans; unsigned int state; void *send_arg; struct link_struct *(*send_cb)(struct link_struct *link, struct lob_struct *packet, void *arg); struct link_struct *next; unsigned char csid; } *links; } *

return_type: int


decompiled_code:
void __fastcall chacha_encrypt_bytes(int *a1, char *a2, char *a3, unsigned int a4)
{
int v4; // eax
int v5; // er14
int v6; // edx
int v7; // ecx
int v8; // er12
int v9; // edi
int v10; // er9
int v11; // er15
int v12; // esi
int v13; // ebx
int v14; // ebp
int v15; // er8
int v16; // er10
int v17; // er11
int v18; // er13
int v19; // er13
int v20; // er11
int v21; // er10
int v22; // ecx
int v23; // edx
int v24; // er9
int v25; // edi
int v26; // eax
int v27; // er12
int v28; // ebp
int v29; // ebx
int v30; // er13
int v31; // er11
int v32; // esi
int v33; // er10
int v34; // ecx
int v35; // edx
int v36; // er9
int v37; // ebp
int v38; // ebx
int v39; // eax
int v40; // er8
int v41; // er13
int v42; // er12
int v43; // edi
int v44; // esi
int v45; // er11
int v46; // er9
int v47; // er15
int v48; // ecx
int v49; // er8
int v50; // edi
int v51; // er9
int v52; // edi
int v53; // er15
int v54; // er9
int v55; // er12
int v56; // er15
int v57; // ebx
int v58; // er10
int v59; // er8
int v60; // esi
int v61; // edx
int v62; // eax
int v63; // er9
int v64; // edi
int v65; // er15
int v66; // ebp
int v67; // er11
int v68; // er10
int v69; // er8
int v70; // ebp
int v71; // ebx
int v72; // er15
int v73; // er9
int v74; // edi
int v75; // er12
int v76; // ecx
int v77; // edx
int v78; // er14
int v79; // eax
__int64 v80; // rax
unsigned int v81; // ecx
__int64 v82; // rdx
char v83; // cl
__int64 i; // rax
int v85; // [rsp+0h] [rbp-ECh]
int v86; // [rsp+0h] [rbp-ECh]
int v87; // [rsp+4h] [rbp-E8h]
int v88; // [rsp+4h] [rbp-E8h]
int v89; // [rsp+8h] [rbp-E4h]
int v90; // [rsp+Ch] [rbp-E0h]
int v91; // [rsp+Ch] [rbp-E0h]
int v92; // [rsp+10h] [rbp-DCh]
unsigned int v93; // [rsp+14h] [rbp-D8h]
int v94; // [rsp+18h] [rbp-D4h]
int v97; // [rsp+2Ch] [rbp-C0h]
int v98; // [rsp+30h] [rbp-BCh]
int v99; // [rsp+34h] [rbp-B8h]
int v100; // [rsp+38h] [rbp-B4h]
int v101; // [rsp+3Ch] [rbp-B0h]
int v102; // [rsp+40h] [rbp-ACh]
int v103; // [rsp+44h] [rbp-A8h]
int v104; // [rsp+48h] [rbp-A4h]
int v105; // [rsp+4Ch] [rbp-A0h]
int v106; // [rsp+50h] [rbp-9Ch]
int v107; // [rsp+54h] [rbp-98h]
int v108; // [rsp+58h] [rbp-94h]
int v109; // [rsp+5Ch] [rbp-90h]
int v110; // [rsp+60h] [rbp-8Ch]
char *v111; // [rsp+64h] [rbp-88h]
unsigned int v113; // [rsp+74h] [rbp-78h]
int v114; // [rsp+78h] [rbp-74h]
char v115[112]; // [rsp+7Ch] [rbp-70h] BYREF

v113 = a4;
if ( a4 )
{
v97 = *a1;
v100 = a1[3];
v98 = a1[1];
v102 = a1[5];
v99 = a1[2];
v104 = a1[7];
v101 = a1[4];
v106 = a1[9];
v103 = a1[6];
v108 = a1[11];
v105 = a1[8];
v114 = a1[12];
v107 = a1[10];
v110 = a1[15];
v94 = a1[13];
v109 = a1[14];
v92 = v114;
v93 = a4;
v111 = 0LL;
if ( a4 <= 0x3F )
goto LABEL_7;
while ( 1 )
{
v4 = v109;
v90 = 10;
v5 = v110;
v6 = v94;
v7 = v92;
v8 = v107;
v89 = v108;
v9 = v106;
v10 = v105;
v11 = v104;
v12 = v103;
v13 = v102;
v14 = v101;
v15 = v100;
v16 = v99;
v17 = v98;
v18 = v97;
do
{
v19 = v14 + v18;
v20 = v13 + v17;
v21 = v12 + v16;
v22 = __ROL4__(v19 ^ v7, 16);
v23 = __ROL4__(v20 ^ v6, 16);
v24 = v22 + v10;
v25 = v23 + v9;
v26 = __ROL4__(v21 ^ v4, 16);
v27 = v26 + v8;
v28 = __ROL4__(v24 ^ v14, 12);
v29 = __ROL4__(v25 ^ v13, 12);
v30 = v28 + v19;
v31 = v29 + v20;
v32 = __ROL4__(v27 ^ v12, 12);
v33 = v32 + v21;
v34 = __ROL4__(v30 ^ v22, 8);
v35 = __ROL4__(v31 ^ v23, 8);
v36 = v34 + v24;
v87 = v35 + v25;
v37 = __ROL4__(v36 ^ v28, 7);
v38 = __ROL4__((v35 + v25) ^ v29, 7);
v85 = v36;
v39 = __ROL4__(v33 ^ v26, 8);
v40 = v11 + v15;
v41 = v38 + v30;
v42 = v39 + v27;
v43 = __ROL4__(v40 ^ v5, 16);
v44 = __ROL4__(v42 ^ v32, 7);
v45 = v44 + v31;
v46 = v43 + v89;
v47 = __ROL4__((v43 + v89) ^ v11, 12);
v48 = __ROL4__(v45 ^ v34, 16);
v49 = v47 + v40;
v50 = __ROL4__(v49 ^ v43, 8);
v51 = v50 + v46;
v52 = __ROL4__(v41 ^ v50, 16);
v53 = v51 ^ v47;
v54 = v48 + v51;
v55 = v52 + v42;
v56 = __ROL4__(v53, 7);
v57 = __ROL4__(v55 ^ v38, 12);
v18 = v57 + v41;
v5 = __ROL4__(v18 ^ v52, 8);
v8 = v5 + v55;
v13 = __ROL4__(v8 ^ v57, 7);
v58 = v56 + v33;
v59 = v37 + v49;
v60 = __ROL4__(v54 ^ v44, 12);
v61 = __ROL4__(v58 ^ v35, 16);
v17 = v60 + v45;
v62 = __ROL4__(v59 ^ v39, 16);
v7 = __ROL4__(v17 ^ v48, 8);
v89 = v54 + v7;
v63 = v61 + v85;
v12 = __ROL4__(v89 ^ v60, 7);
v64 = v62 + v87;
v65 = __ROL4__((v61 + v85) ^ v56, 12);
v66 = __ROL4__((v62 + v87) ^ v37, 12);
v16 = v65 + v58;
v15 = v66 + v59;
v6 = __ROL4__(v16 ^ v61, 8);
v4 = __ROL4__(v15 ^ v62, 8);
v10 = v6 + v63;
v9 = v4 + v64;
v11 = __ROL4__(v10 ^ v65, 7);
v14 = __ROL4__(v9 ^ v66, 7);
--v90;
}
while ( v90 );
v67 = *((_DWORD *)a2 + 1) ^ (v98 + v17);
v68 = *((_DWORD *)a2 + 2) ^ (v99 + v16);
v69 = *((_DWORD *)a2 + 3) ^ (v100 + v15);
v70 = *((_DWORD *)a2 + 4) ^ (v101 + v14);
v71 = *((_DWORD *)a2 + 5) ^ (v102 + v13);
v91 = (v97 + v18) ^ *(_DWORD *)a2;
v72 = *((_DWORD *)a2 + 7) ^ (v104 + v11);
v86 = *((_DWORD *)a2 + 6) ^ (v103 + v12);
v73 = *((_DWORD *)a2 + 8) ^ (v105 + v10);
v74 = *((_DWORD *)a2 + 9) ^ (v106 + v9);
v75 = *((_DWORD *)a2 + 10) ^ (v107 + v8);
v76 = *((_DWORD *)a2 + 12) ^ (v92 + v7);
v77 = *((_DWORD *)a2 + 13) ^ (v94 + v6);
v88 = *((_DWORD *)a2 + 11) ^ (v108 + v89);
v78 = *((_DWORD *)a2 + 15) ^ (v110 + v5);
v79 = *((_DWORD *)a2 + 14) ^ (v109 + v4);
v94 += ++v92 == 0;
*(_DWORD *)a3 = v91;
*((_DWORD *)a3 + 1) = v67;
*((_DWORD *)a3 + 6) = v86;
*((_DWORD *)a3 + 2) = v68;
*((_DWORD *)a3 + 3) = v69;
*((_DWORD *)a3 + 4) = v70;
*((_DWORD *)a3 + 5) = v71;
*((_DWORD *)a3 + 7) = v72;
*((_DWORD *)a3 + 8) = v73;
*((_DWORD *)a3 + 9) = v74;
*((_DWORD *)a3 + 10) = v75;
*((_DWORD *)a3 + 11) = v88;
*((_DWORD *)a3 + 12) = v76;
*((_DWORD *)a3 + 13) = v77;
*((_DWORD *)a3 + 14) = v79;
*((_DWORD *)a3 + 15) = v78;
if ( v93 <= 0x40 )
break;
v93 -= 64;
a3 += 64;
a2 += 64;
if ( v93 <= 0x3F )
{
LABEL_7:
v80 = 0LL;
do
{
v115[v80] = a2[v80];
++v80;
}
while ( v93 != v80 );
v111 = a3;
a3 = v115;
a2 = v115;
}
}
v81 = v113 - ((v113 - 1) & 0xFFFFFFC0);
if ( v81 != 64 )
{
v82 = v81;
v83 = v91;
for ( i = 0LL; ; v83 = a3[i] )
{
v111[i++] = v83;
if ( i == v82 )
break;
}
}
a1[12] = ((v113 - 1) >> 6) + v114 + 1;
a1[13] = v94;
}
}

canonical_decompiled_code:
void __fastcall func2(int *a1, char *a2, char *a3, unsigned int a4)
{
int v4; // eax
int v5; // er14
int v6; // edx
int v7; // ecx
int v8; // er12
int v9; // edi
int v10; // er9
int v11; // er15
int v12; // esi
int v13; // ebx
int v14; // ebp
int v15; // er8
int v16; // er10
int v17; // er11
int v18; // er13
int v19; // er13
int v20; // er11
int v21; // er10
int v22; // ecx
int v23; // edx
int v24; // er9
int v25; // edi
int v26; // eax
int v27; // er12
int v28; // ebp
int v29; // ebx
int v30; // er13
int v31; // er11
int v32; // esi
int v33; // er10
int v34; // ecx
int v35; // edx
int v36; // er9
int v37; // ebp
int v38; // ebx
int v39; // eax
int v40; // er8
int v41; // er13
int v42; // er12
int v43; // edi
int v44; // esi
int v45; // er11
int v46; // er9
int v47; // er15
int v48; // ecx
int v49; // er8
int v50; // edi
int v51; // er9
int v52; // edi
int v53; // er15
int v54; // er9
int v55; // er12
int v56; // er15
int v57; // ebx
int v58; // er10
int v59; // er8
int v60; // esi
int v61; // edx
int v62; // eax
int v63; // er9
int v64; // edi
int v65; // er15
int v66; // ebp
int v67; // er11
int v68; // er10
int v69; // er8
int v70; // ebp
int v71; // ebx
int v72; // er15
int v73; // er9
int v74; // edi
int v75; // er12
int v76; // ecx
int v77; // edx
int v78; // er14
int v79; // eax
__int64 v80; // rax
unsigned int v81; // ecx
__int64 v82; // rdx
char v83; // cl
__int64 i; // rax
int v85; // [rsp+0h] [rbp-ECh]
int v86; // [rsp+0h] [rbp-ECh]
int v87; // [rsp+4h] [rbp-E8h]
int v88; // [rsp+4h] [rbp-E8h]
int v89; // [rsp+8h] [rbp-E4h]
int v90; // [rsp+Ch] [rbp-E0h]
int v91; // [rsp+Ch] [rbp-E0h]
int v92; // [rsp+10h] [rbp-DCh]
unsigned int v93; // [rsp+14h] [rbp-D8h]
int v94; // [rsp+18h] [rbp-D4h]
int v97; // [rsp+2Ch] [rbp-C0h]
int v98; // [rsp+30h] [rbp-BCh]
int v99; // [rsp+34h] [rbp-B8h]
int v100; // [rsp+38h] [rbp-B4h]
int v101; // [rsp+3Ch] [rbp-B0h]
int v102; // [rsp+40h] [rbp-ACh]
int v103; // [rsp+44h] [rbp-A8h]
int v104; // [rsp+48h] [rbp-A4h]
int v105; // [rsp+4Ch] [rbp-A0h]
int v106; // [rsp+50h] [rbp-9Ch]
int v107; // [rsp+54h] [rbp-98h]
int v108; // [rsp+58h] [rbp-94h]
int v109; // [rsp+5Ch] [rbp-90h]
int v110; // [rsp+60h] [rbp-8Ch]
char *v111; // [rsp+64h] [rbp-88h]
unsigned int v113; // [rsp+74h] [rbp-78h]
int v114; // [rsp+78h] [rbp-74h]
char v115[112]; // [rsp+7Ch] [rbp-70h] BYREF

v113 = a4;
if ( a4 )
{
v97 = *a1;
v100 = a1[3];
v98 = a1[1];
v102 = a1[5];
v99 = a1[2];
v104 = a1[7];
v101 = a1[4];
v106 = a1[9];
v103 = a1[6];
v108 = a1[11];
v105 = a1[8];
v114 = a1[12];
v107 = a1[10];
v110 = a1[15];
v94 = a1[13];
v109 = a1[14];
v92 = v114;
v93 = a4;
v111 = 0LL;
if ( a4 <= 0x3F )
goto LABEL_7;
while ( 1 )
{
v4 = v109;
v90 = 10;
v5 = v110;
v6 = v94;
v7 = v92;
v8 = v107;
v89 = v108;
v9 = v106;
v10 = v105;
v11 = v104;
v12 = v103;
v13 = v102;
v14 = v101;
v15 = v100;
v16 = v99;
v17 = v98;
v18 = v97;
do
{
v19 = v14 + v18;
v20 = v13 + v17;
v21 = v12 + v16;
v22 = __ROL4__(v19 ^ v7, 16);
v23 = __ROL4__(v20 ^ v6, 16);
v24 = v22 + v10;
v25 = v23 + v9;
v26 = __ROL4__(v21 ^ v4, 16);
v27 = v26 + v8;
v28 = __ROL4__(v24 ^ v14, 12);
v29 = __ROL4__(v25 ^ v13, 12);
v30 = v28 + v19;
v31 = v29 + v20;
v32 = __ROL4__(v27 ^ v12, 12);
v33 = v32 + v21;
v34 = __ROL4__(v30 ^ v22, 8);
v35 = __ROL4__(v31 ^ v23, 8);
v36 = v34 + v24;
v87 = v35 + v25;
v37 = __ROL4__(v36 ^ v28, 7);
v38 = __ROL4__((v35 + v25) ^ v29, 7);
v85 = v36;
v39 = __ROL4__(v33 ^ v26, 8);
v40 = v11 + v15;
v41 = v38 + v30;
v42 = v39 + v27;
v43 = __ROL4__(v40 ^ v5, 16);
v44 = __ROL4__(v42 ^ v32, 7);
v45 = v44 + v31;
v46 = v43 + v89;
v47 = __ROL4__((v43 + v89) ^ v11, 12);
v48 = __ROL4__(v45 ^ v34, 16);
v49 = v47 + v40;
v50 = __ROL4__(v49 ^ v43, 8);
v51 = v50 + v46;
v52 = __ROL4__(v41 ^ v50, 16);
v53 = v51 ^ v47;
v54 = v48 + v51;
v55 = v52 + v42;
v56 = __ROL4__(v53, 7);
v57 = __ROL4__(v55 ^ v38, 12);
v18 = v57 + v41;
v5 = __ROL4__(v18 ^ v52, 8);
v8 = v5 + v55;
v13 = __ROL4__(v8 ^ v57, 7);
v58 = v56 + v33;
v59 = v37 + v49;
v60 = __ROL4__(v54 ^ v44, 12);
v61 = __ROL4__(v58 ^ v35, 16);
v17 = v60 + v45;
v62 = __ROL4__(v59 ^ v39, 16);
v7 = __ROL4__(v17 ^ v48, 8);
v89 = v54 + v7;
v63 = v61 + v85;
v12 = __ROL4__(v89 ^ v60, 7);
v64 = v62 + v87;
v65 = __ROL4__((v61 + v85) ^ v56, 12);
v66 = __ROL4__((v62 + v87) ^ v37, 12);
v16 = v65 + v58;
v15 = v66 + v59;
v6 = __ROL4__(v16 ^ v61, 8);
v4 = __ROL4__(v15 ^ v62, 8);
v10 = v6 + v63;
v9 = v4 + v64;
v11 = __ROL4__(v10 ^ v65, 7);
v14 = __ROL4__(v9 ^ v66, 7);
--v90;
}
while ( v90 );
v67 = *((_DWORD *)a2 + 1) ^ (v98 + v17);
v68 = *((_DWORD *)a2 + 2) ^ (v99 + v16);
v69 = *((_DWORD *)a2 + 3) ^ (v100 + v15);
v70 = *((_DWORD *)a2 + 4) ^ (v101 + v14);
v71 = *((_DWORD *)a2 + 5) ^ (v102 + v13);
v91 = (v97 + v18) ^ *(_DWORD *)a2;
v72 = *((_DWORD *)a2 + 7) ^ (v104 + v11);
v86 = *((_DWORD *)a2 + 6) ^ (v103 + v12);
v73 = *((_DWORD *)a2 + 8) ^ (v105 + v10);
v74 = *((_DWORD *)a2 + 9) ^ (v106 + v9);
v75 = *((_DWORD *)a2 + 10) ^ (v107 + v8);
v76 = *((_DWORD *)a2 + 12) ^ (v92 + v7);
v77 = *((_DWORD *)a2 + 13) ^ (v94 + v6);
v88 = *((_DWORD *)a2 + 11) ^ (v108 + v89);
v78 = *((_DWORD *)a2 + 15) ^ (v110 + v5);
v79 = *((_DWORD *)a2 + 14) ^ (v109 + v4);
v94 += ++v92 == 0;
*(_DWORD *)a3 = v91;
*((_DWORD *)a3 + 1) = v67;
*((_DWORD *)a3 + 6) = v86;
*((_DWORD *)a3 + 2) = v68;
*((_DWORD *)a3 + 3) = v69;
*((_DWORD *)a3 + 4) = v70;
*((_DWORD *)a3 + 5) = v71;
*((_DWORD *)a3 + 7) = v72;
*((_DWORD *)a3 + 8) = v73;
*((_DWORD *)a3 + 9) = v74;
*((_DWORD *)a3 + 10) = v75;
*((_DWORD *)a3 + 11) = v88;
*((_DWORD *)a3 + 12) = v76;
*((_DWORD *)a3 + 13) = v77;
*((_DWORD *)a3 + 14) = v79;
*((_DWORD *)a3 + 15) = v78;
if ( v93 <= 0x40 )
break;
v93 -= 64;
a3 += 64;
a2 += 64;
if ( v93 <= 0x3F )
{
LABEL_7:
v80 = 0LL;
do
{
v115[v80] = a2[v80];
++v80;
}
while ( v93 != v80 );
v111 = a3;
a3 = v115;
a2 = v115;
}
}
v81 = v113 - ((v113 - 1) & 0xFFFFFFC0);
if ( v81 != 64 )
{
v82 = v81;
v83 = v91;
for ( i = 0LL; ; v83 = a3[i] )
{
v111[i++] = v83;
if ( i == v82 )
break;
}
}
a1[12] = ((v113 - 1) >> 6) + v114 + 1;
a1[13] = v94;
}
}

canonical_original_code:
void chacha_encrypt_bytes(struct chacha_ctx *x, unsigned char *m, unsigned char *c, unsigned int bytes)
{
 unsigned int x0; unsigned int x1; unsigned int x2; unsigned int x3; unsigned int x4; unsigned int x5; unsigned int x6; unsigned int x7; unsigned int x8; unsigned int x9; unsigned int x10; unsigned int x11; unsigned int x12; unsigned int x13; unsigned int x14; unsigned int x15;
 unsigned int j0; unsigned int j1; unsigned int j2; unsigned int j3; unsigned int j4; unsigned int j5; unsigned int j6; unsigned int j7; unsigned int j8; unsigned int j9; unsigned int j10; unsigned int j11; unsigned int j12; unsigned int j13; unsigned int j14; unsigned int j15;
 unsigned char *ctarget = ((void *)0);
 unsigned char tmp[64];
 unsigned int i;
 if (!bytes)
  return;
 j0 = x->input[0];
 j1 = x->input[1];
 j2 = x->input[2];
 j3 = x->input[3];
 j4 = x->input[4];
 j5 = x->input[5];
 j6 = x->input[6];
 j7 = x->input[7];
 j8 = x->input[8];
 j9 = x->input[9];
 j10 = x->input[10];
 j11 = x->input[11];
 j12 = x->input[12];
 j13 = x->input[13];
 j14 = x->input[14];
 j15 = x->input[15];
 for (;;) {
  if (bytes < 64) {
   for (i = 0; i < bytes; ++i)
    tmp[i] = m[i];
   m = tmp;
   ctarget = c;
   c = tmp;
  }
  x0 = j0;
  x1 = j1;
  x2 = j2;
  x3 = j3;
  x4 = j4;
  x5 = j5;
  x6 = j6;
  x7 = j7;
  x8 = j8;
  x9 = j9;
  x10 = j10;
  x11 = j11;
  x12 = j12;
  x13 = j13;
  x14 = j14;
  x15 = j15;
  for (i = 20; i > 0; i -= 2) {
   x0 = (((u32)((x0) + (x4)) & (0xFFFFFFFFU))); x12 = ((((u32)((((x12) ^ (x0))) << (16)) & (0xFFFFFFFFU)) | ((((x12) ^ (x0))) >> (32 - (16))))); x8 = (((u32)((x8) + (x12)) & (0xFFFFFFFFU))); x4 = ((((u32)((((x4) ^ (x8))) << (12)) & (0xFFFFFFFFU)) | ((((x4) ^ (x8))) >> (32 - (12))))); x0 = (((u32)((x0) + (x4)) & (0xFFFFFFFFU))); x12 = ((((u32)((((x12) ^ (x0))) << (8)) & (0xFFFFFFFFU)) | ((((x12) ^ (x0))) >> (32 - (8))))); x8 = (((u32)((x8) + (x12)) & (0xFFFFFFFFU))); x4 = ((((u32)((((x4) ^ (x8))) << (7)) & (0xFFFFFFFFU)) | ((((x4) ^ (x8))) >> (32 - (7)))));
   x1 = (((u32)((x1) + (x5)) & (0xFFFFFFFFU))); x13 = ((((u32)((((x13) ^ (x1))) << (16)) & (0xFFFFFFFFU)) | ((((x13) ^ (x1))) >> (32 - (16))))); x9 = (((u32)((x9) + (x13)) & (0xFFFFFFFFU))); x5 = ((((u32)((((x5) ^ (x9))) << (12)) & (0xFFFFFFFFU)) | ((((x5) ^ (x9))) >> (32 - (12))))); x1 = (((u32)((x1) + (x5)) & (0xFFFFFFFFU))); x13 = ((((u32)((((x13) ^ (x1))) << (8)) & (0xFFFFFFFFU)) | ((((x13) ^ (x1))) >> (32 - (8))))); x9 = (((u32)((x9) + (x13)) & (0xFFFFFFFFU))); x5 = ((((u32)((((x5) ^ (x9))) << (7)) & (0xFFFFFFFFU)) | ((((x5) ^ (x9))) >> (32 - (7)))));
   x2 = (((u32)((x2) + (x6)) & (0xFFFFFFFFU))); x14 = ((((u32)((((x14) ^ (x2))) << (16)) & (0xFFFFFFFFU)) | ((((x14) ^ (x2))) >> (32 - (16))))); x10 = (((u32)((x10) + (x14)) & (0xFFFFFFFFU))); x6 = ((((u32)((((x6) ^ (x10))) << (12)) & (0xFFFFFFFFU)) | ((((x6) ^ (x10))) >> (32 - (12))))); x2 = (((u32)((x2) + (x6)) & (0xFFFFFFFFU))); x14 = ((((u32)((((x14) ^ (x2))) << (8)) & (0xFFFFFFFFU)) | ((((x14) ^ (x2))) >> (32 - (8))))); x10 = (((u32)((x10) + (x14)) & (0xFFFFFFFFU))); x6 = ((((u32)((((x6) ^ (x10))) << (7)) & (0xFFFFFFFFU)) | ((((x6) ^ (x10))) >> (32 - (7)))));
   x3 = (((u32)((x3) + (x7)) & (0xFFFFFFFFU))); x15 = ((((u32)((((x15) ^ (x3))) << (16)) & (0xFFFFFFFFU)) | ((((x15) ^ (x3))) >> (32 - (16))))); x11 = (((u32)((x11) + (x15)) & (0xFFFFFFFFU))); x7 = ((((u32)((((x7) ^ (x11))) << (12)) & (0xFFFFFFFFU)) | ((((x7) ^ (x11))) >> (32 - (12))))); x3 = (((u32)((x3) + (x7)) & (0xFFFFFFFFU))); x15 = ((((u32)((((x15) ^ (x3))) << (8)) & (0xFFFFFFFFU)) | ((((x15) ^ (x3))) >> (32 - (8))))); x11 = (((u32)((x11) + (x15)) & (0xFFFFFFFFU))); x7 = ((((u32)((((x7) ^ (x11))) << (7)) & (0xFFFFFFFFU)) | ((((x7) ^ (x11))) >> (32 - (7)))));
   x0 = (((u32)((x0) + (x5)) & (0xFFFFFFFFU))); x15 = ((((u32)((((x15) ^ (x0))) << (16)) & (0xFFFFFFFFU)) | ((((x15) ^ (x0))) >> (32 - (16))))); x10 = (((u32)((x10) + (x15)) & (0xFFFFFFFFU))); x5 = ((((u32)((((x5) ^ (x10))) << (12)) & (0xFFFFFFFFU)) | ((((x5) ^ (x10))) >> (32 - (12))))); x0 = (((u32)((x0) + (x5)) & (0xFFFFFFFFU))); x15 = ((((u32)((((x15) ^ (x0))) << (8)) & (0xFFFFFFFFU)) | ((((x15) ^ (x0))) >> (32 - (8))))); x10 = (((u32)((x10) + (x15)) & (0xFFFFFFFFU))); x5 = ((((u32)((((x5) ^ (x10))) << (7)) & (0xFFFFFFFFU)) | ((((x5) ^ (x10))) >> (32 - (7)))));
   x1 = (((u32)((x1) + (x6)) & (0xFFFFFFFFU))); x12 = ((((u32)((((x12) ^ (x1))) << (16)) & (0xFFFFFFFFU)) | ((((x12) ^ (x1))) >> (32 - (16))))); x11 = (((u32)((x11) + (x12)) & (0xFFFFFFFFU))); x6 = ((((u32)((((x6) ^ (x11))) << (12)) & (0xFFFFFFFFU)) | ((((x6) ^ (x11))) >> (32 - (12))))); x1 = (((u32)((x1) + (x6)) & (0xFFFFFFFFU))); x12 = ((((u32)((((x12) ^ (x1))) << (8)) & (0xFFFFFFFFU)) | ((((x12) ^ (x1))) >> (32 - (8))))); x11 = (((u32)((x11) + (x12)) & (0xFFFFFFFFU))); x6 = ((((u32)((((x6) ^ (x11))) << (7)) & (0xFFFFFFFFU)) | ((((x6) ^ (x11))) >> (32 - (7)))));
   x2 = (((u32)((x2) + (x7)) & (0xFFFFFFFFU))); x13 = ((((u32)((((x13) ^ (x2))) << (16)) & (0xFFFFFFFFU)) | ((((x13) ^ (x2))) >> (32 - (16))))); x8 = (((u32)((x8) + (x13)) & (0xFFFFFFFFU))); x7 = ((((u32)((((x7) ^ (x8))) << (12)) & (0xFFFFFFFFU)) | ((((x7) ^ (x8))) >> (32 - (12))))); x2 = (((u32)((x2) + (x7)) & (0xFFFFFFFFU))); x13 = ((((u32)((((x13) ^ (x2))) << (8)) & (0xFFFFFFFFU)) | ((((x13) ^ (x2))) >> (32 - (8))))); x8 = (((u32)((x8) + (x13)) & (0xFFFFFFFFU))); x7 = ((((u32)((((x7) ^ (x8))) << (7)) & (0xFFFFFFFFU)) | ((((x7) ^ (x8))) >> (32 - (7)))));
   x3 = (((u32)((x3) + (x4)) & (0xFFFFFFFFU))); x14 = ((((u32)((((x14) ^ (x3))) << (16)) & (0xFFFFFFFFU)) | ((((x14) ^ (x3))) >> (32 - (16))))); x9 = (((u32)((x9) + (x14)) & (0xFFFFFFFFU))); x4 = ((((u32)((((x4) ^ (x9))) << (12)) & (0xFFFFFFFFU)) | ((((x4) ^ (x9))) >> (32 - (12))))); x3 = (((u32)((x3) + (x4)) & (0xFFFFFFFFU))); x14 = ((((u32)((((x14) ^ (x3))) << (8)) & (0xFFFFFFFFU)) | ((((x14) ^ (x3))) >> (32 - (8))))); x9 = (((u32)((x9) + (x14)) & (0xFFFFFFFFU))); x4 = ((((u32)((((x4) ^ (x9))) << (7)) & (0xFFFFFFFFU)) | ((((x4) ^ (x9))) >> (32 - (7)))));
  }
  x0 = (((u32)((x0) + (j0)) & (0xFFFFFFFFU)));
  x1 = (((u32)((x1) + (j1)) & (0xFFFFFFFFU)));
  x2 = (((u32)((x2) + (j2)) & (0xFFFFFFFFU)));
  x3 = (((u32)((x3) + (j3)) & (0xFFFFFFFFU)));
  x4 = (((u32)((x4) + (j4)) & (0xFFFFFFFFU)));
  x5 = (((u32)((x5) + (j5)) & (0xFFFFFFFFU)));
  x6 = (((u32)((x6) + (j6)) & (0xFFFFFFFFU)));
  x7 = (((u32)((x7) + (j7)) & (0xFFFFFFFFU)));
  x8 = (((u32)((x8) + (j8)) & (0xFFFFFFFFU)));
  x9 = (((u32)((x9) + (j9)) & (0xFFFFFFFFU)));
  x10 = (((u32)((x10) + (j10)) & (0xFFFFFFFFU)));
  x11 = (((u32)((x11) + (j11)) & (0xFFFFFFFFU)));
  x12 = (((u32)((x12) + (j12)) & (0xFFFFFFFFU)));
  x13 = (((u32)((x13) + (j13)) & (0xFFFFFFFFU)));
  x14 = (((u32)((x14) + (j14)) & (0xFFFFFFFFU)));
  x15 = (((u32)((x15) + (j15)) & (0xFFFFFFFFU)));
  x0 = ((x0) ^ ((((u32)((m + 0)[0]) ) | ((u32)((m + 0)[1]) << 8) | ((u32)((m + 0)[2]) << 16) | ((u32)((m + 0)[3]) << 24))));
  x1 = ((x1) ^ ((((u32)((m + 4)[0]) ) | ((u32)((m + 4)[1]) << 8) | ((u32)((m + 4)[2]) << 16) | ((u32)((m + 4)[3]) << 24))));
  x2 = ((x2) ^ ((((u32)((m + 8)[0]) ) | ((u32)((m + 8)[1]) << 8) | ((u32)((m + 8)[2]) << 16) | ((u32)((m + 8)[3]) << 24))));
  x3 = ((x3) ^ ((((u32)((m + 12)[0]) ) | ((u32)((m + 12)[1]) << 8) | ((u32)((m + 12)[2]) << 16) | ((u32)((m + 12)[3]) << 24))));
  x4 = ((x4) ^ ((((u32)((m + 16)[0]) ) | ((u32)((m + 16)[1]) << 8) | ((u32)((m + 16)[2]) << 16) | ((u32)((m + 16)[3]) << 24))));
  x5 = ((x5) ^ ((((u32)((m + 20)[0]) ) | ((u32)((m + 20)[1]) << 8) | ((u32)((m + 20)[2]) << 16) | ((u32)((m + 20)[3]) << 24))));
  x6 = ((x6) ^ ((((u32)((m + 24)[0]) ) | ((u32)((m + 24)[1]) << 8) | ((u32)((m + 24)[2]) << 16) | ((u32)((m + 24)[3]) << 24))));
  x7 = ((x7) ^ ((((u32)((m + 28)[0]) ) | ((u32)((m + 28)[1]) << 8) | ((u32)((m + 28)[2]) << 16) | ((u32)((m + 28)[3]) << 24))));
  x8 = ((x8) ^ ((((u32)((m + 32)[0]) ) | ((u32)((m + 32)[1]) << 8) | ((u32)((m + 32)[2]) << 16) | ((u32)((m + 32)[3]) << 24))));
  x9 = ((x9) ^ ((((u32)((m + 36)[0]) ) | ((u32)((m + 36)[1]) << 8) | ((u32)((m + 36)[2]) << 16) | ((u32)((m + 36)[3]) << 24))));
  x10 = ((x10) ^ ((((u32)((m + 40)[0]) ) | ((u32)((m + 40)[1]) << 8) | ((u32)((m + 40)[2]) << 16) | ((u32)((m + 40)[3]) << 24))));
  x11 = ((x11) ^ ((((u32)((m + 44)[0]) ) | ((u32)((m + 44)[1]) << 8) | ((u32)((m + 44)[2]) << 16) | ((u32)((m + 44)[3]) << 24))));
  x12 = ((x12) ^ ((((u32)((m + 48)[0]) ) | ((u32)((m + 48)[1]) << 8) | ((u32)((m + 48)[2]) << 16) | ((u32)((m + 48)[3]) << 24))));
  x13 = ((x13) ^ ((((u32)((m + 52)[0]) ) | ((u32)((m + 52)[1]) << 8) | ((u32)((m + 52)[2]) << 16) | ((u32)((m + 52)[3]) << 24))));
  x14 = ((x14) ^ ((((u32)((m + 56)[0]) ) | ((u32)((m + 56)[1]) << 8) | ((u32)((m + 56)[2]) << 16) | ((u32)((m + 56)[3]) << 24))));
  x15 = ((x15) ^ ((((u32)((m + 60)[0]) ) | ((u32)((m + 60)[1]) << 8) | ((u32)((m + 60)[2]) << 16) | ((u32)((m + 60)[3]) << 24))));
  j12 = ((((u32)(((j12)) + (1)) & (0xFFFFFFFFU))));
  if (!j12) {
   j13 = ((((u32)(((j13)) + (1)) & (0xFFFFFFFFU))));
  }
  do { (c + 0)[0] = ((u8)((x0)) & (0xFFU)); (c + 0)[1] = ((u8)((x0) >> 8) & (0xFFU)); (c + 0)[2] = ((u8)((x0) >> 16) & (0xFFU)); (c + 0)[3] = ((u8)((x0) >> 24) & (0xFFU)); } while (0);
  do { (c + 4)[0] = ((u8)((x1)) & (0xFFU)); (c + 4)[1] = ((u8)((x1) >> 8) & (0xFFU)); (c + 4)[2] = ((u8)((x1) >> 16) & (0xFFU)); (c + 4)[3] = ((u8)((x1) >> 24) & (0xFFU)); } while (0);
  do { (c + 8)[0] = ((u8)((x2)) & (0xFFU)); (c + 8)[1] = ((u8)((x2) >> 8) & (0xFFU)); (c + 8)[2] = ((u8)((x2) >> 16) & (0xFFU)); (c + 8)[3] = ((u8)((x2) >> 24) & (0xFFU)); } while (0);
  do { (c + 12)[0] = ((u8)((x3)) & (0xFFU)); (c + 12)[1] = ((u8)((x3) >> 8) & (0xFFU)); (c + 12)[2] = ((u8)((x3) >> 16) & (0xFFU)); (c + 12)[3] = ((u8)((x3) >> 24) & (0xFFU)); } while (0);
  do { (c + 16)[0] = ((u8)((x4)) & (0xFFU)); (c + 16)[1] = ((u8)((x4) >> 8) & (0xFFU)); (c + 16)[2] = ((u8)((x4) >> 16) & (0xFFU)); (c + 16)[3] = ((u8)((x4) >> 24) & (0xFFU)); } while (0);
  do { (c + 20)[0] = ((u8)((x5)) & (0xFFU)); (c + 20)[1] = ((u8)((x5) >> 8) & (0xFFU)); (c + 20)[2] = ((u8)((x5) >> 16) & (0xFFU)); (c + 20)[3] = ((u8)((x5) >> 24) & (0xFFU)); } while (0);
  do { (c + 24)[0] = ((u8)((x6)) & (0xFFU)); (c + 24)[1] = ((u8)((x6) >> 8) & (0xFFU)); (c + 24)[2] = ((u8)((x6) >> 16) & (0xFFU)); (c + 24)[3] = ((u8)((x6) >> 24) & (0xFFU)); } while (0);
  do { (c + 28)[0] = ((u8)((x7)) & (0xFFU)); (c + 28)[1] = ((u8)((x7) >> 8) & (0xFFU)); (c + 28)[2] = ((u8)((x7) >> 16) & (0xFFU)); (c + 28)[3] = ((u8)((x7) >> 24) & (0xFFU)); } while (0);
  do { (c + 32)[0] = ((u8)((x8)) & (0xFFU)); (c + 32)[1] = ((u8)((x8) >> 8) & (0xFFU)); (c + 32)[2] = ((u8)((x8) >> 16) & (0xFFU)); (c + 32)[3] = ((u8)((x8) >> 24) & (0xFFU)); } while (0);
  do { (c + 36)[0] = ((u8)((x9)) & (0xFFU)); (c + 36)[1] = ((u8)((x9) >> 8) & (0xFFU)); (c + 36)[2] = ((u8)((x9) >> 16) & (0xFFU)); (c + 36)[3] = ((u8)((x9) >> 24) & (0xFFU)); } while (0);
  do { (c + 40)[0] = ((u8)((x10)) & (0xFFU)); (c + 40)[1] = ((u8)((x10) >> 8) & (0xFFU)); (c + 40)[2] = ((u8)((x10) >> 16) & (0xFFU)); (c + 40)[3] = ((u8)((x10) >> 24) & (0xFFU)); } while (0);
  do { (c + 44)[0] = ((u8)((x11)) & (0xFFU)); (c + 44)[1] = ((u8)((x11) >> 8) & (0xFFU)); (c + 44)[2] = ((u8)((x11) >> 16) & (0xFFU)); (c + 44)[3] = ((u8)((x11) >> 24) & (0xFFU)); } while (0);
  do { (c + 48)[0] = ((u8)((x12)) & (0xFFU)); (c + 48)[1] = ((u8)((x12) >> 8) & (0xFFU)); (c + 48)[2] = ((u8)((x12) >> 16) & (0xFFU)); (c + 48)[3] = ((u8)((x12) >> 24) & (0xFFU)); } while (0);
  do { (c + 52)[0] = ((u8)((x13)) & (0xFFU)); (c + 52)[1] = ((u8)((x13) >> 8) & (0xFFU)); (c + 52)[2] = ((u8)((x13) >> 16) & (0xFFU)); (c + 52)[3] = ((u8)((x13) >> 24) & (0xFFU)); } while (0);
  do { (c + 56)[0] = ((u8)((x14)) & (0xFFU)); (c + 56)[1] = ((u8)((x14) >> 8) & (0xFFU)); (c + 56)[2] = ((u8)((x14) >> 16) & (0xFFU)); (c + 56)[3] = ((u8)((x14) >> 24) & (0xFFU)); } while (0);
  do { (c + 60)[0] = ((u8)((x15)) & (0xFFU)); (c + 60)[1] = ((u8)((x15) >> 8) & (0xFFU)); (c + 60)[2] = ((u8)((x15) >> 16) & (0xFFU)); (c + 60)[3] = ((u8)((x15) >> 24) & (0xFFU)); } while (0);
  if (bytes <= 64) {
   if (bytes < 64) {
    for (i = 0; i < bytes; ++i)
     ctarget[i] = c[i];
   }
   x->input[12] = j12;
   x->input[13] = j13;
   return;
  }
  bytes -= 64;
  c += 64;
  m += 64;
 }
}

variable_types: struct chacha_ctx { unsigned int input[16]; } *

variable_types:
m
unsigned char *

variable_types:
c
unsigned char *

variable_types:
bytes
unsigned int

variable_types:
ctarget
unsigned char *

variable_types:
tmp
unsigned char [64]

variable_types:
i
unsigned int


variable_types:
k
unsigned char *

variable_types:
kbits
unsigned int

variable_types:
constants
char *

user_defined_types: struct chacha_ctx { unsigned int input[16]; }


decompiled_code:
__int64 __fastcall net_loopback_new(__int64 a1, __int64 a2)
{
_QWORD *v3; // rax
__int64 v4; // rsi
_QWORD *v5; // r12
__int64 v6; // rax
__int64 v7; // rax

v3 = malloc(0x10uLL);
if ( !v3 )
return util_sys_log(7LL, "src/net/loopback.c", 19LL, "net_loopback_new", "OOM");
*v3 = a1;
v4 = *(_QWORD *)(a2 + 8);
v5 = v3;
v3[1] = a2;
v6 = link_get_keys(a1, v4);
link_pipe(v6, pair_send, v5);
v7 = link_get_keys(a2, *(_QWORD *)(a1 + 8));
link_pipe(v7, pair_send, v5);
return (__int64)v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
_QWORD *v3; // rax
__int64 v4; // rsi
_QWORD *v5; // r12
__int64 v6; // rax
__int64 v7; // rax

v3 = malloc(0x10uLL);
if ( !v3 )
return util_sys_log(7LL, "src/net/loopback.c", 19LL, "net_loopback_new", "OOM");
*v3 = a1;
v4 = *(_QWORD *)(a2 + 8);
v5 = v3;
v3[1] = a2;
v6 = link_get_keys(a1, v4);
link_pipe(v6, pair_send, v5);
v7 = link_get_keys(a2, *(_QWORD *)(a1 + 8));
link_pipe(v7, pair_send, v5);
return (__int64)v5;
}

original_code:
net_loopback_t net_loopback_new(mesh_t a, mesh_t b)
{
  net_loopback_t pair;
  if(!(pair = malloc(sizeof (struct net_loopback_struct)))) return util_sys_log(7, "src/net/loopback.c", 19, __func__, "OOM");
  memset(pair,0,sizeof (struct net_loopback_struct));
  pair->a = a;
  pair->b = b;
  link_pipe(link_get_keys(a,b->keys),pair_send,pair);
  link_pipe(link_get_keys(b,a->keys),pair_send,pair);
  return pair;
}

canonical_original_code:
struct net_loopback_struct *net_loopback_new(struct mesh_struct *a, struct mesh_struct *b)
{
  struct net_loopback_struct *pair;
  if(!(pair = malloc(sizeof (struct net_loopback_struct)))) return util_sys_log(7, "src/net/loopback.c", 19, __func__, "OOM");
  memset(pair,0,sizeof (struct net_loopback_struct));
  pair->a = a;
  pair->b = b;
  link_pipe(link_get_keys(a,b->keys),pair_send,pair);
  link_pipe(link_get_keys(b,a->keys),pair_send,pair);
  return pair;
}

variable_types:
a
struct mesh_struct *

variable_types:
b
struct mesh_struct *

variable_types: struct net_loopback_struct { struct mesh_struct { struct hashname_struct { unsigned char bin[32]; } *id; struct lob_struct { unsigned char *raw; unsigned char *body; unsigned long body_len; unsigned char *head; unsigned long head_len; unsigned int id; void *arg; struct lob_struct *chain; char *cache; struct lob_struct *next; } *keys; struct e3x_self_struct { struct lob_struct *keys[2]; void *locals[2]; } *self; void *on; unsigned int state; struct link_struct { struct hashname_struct *id; struct e3x_exchange_struct { struct e3x_cipher_struct { unsigned char *(*rand)(unsigned char *bytes, unsigned long len); unsigned char *(*hash)(unsigned char *in, unsigned long len, unsigned char *out32); unsigned char *(*err)(); unsigned char (*generate)(struct lob_struct *keys, struct lob_struct *secrets); void *(*local_new)(struct lob_struct *keys, struct lob_struct *secrets); void (*local_free)(void *local); struct lob_struct *(*local_decrypt)(void *local, struct lob_struct *outer); struct lob_struct *(*local_sign)(void *local, struct lob_struct *args, unsigned char *data, unsigned long len); void *(*remote_new)(struct lob_struct *key, unsigned char *token); void (*remote_free)(void *remote); unsigned char (*remote_verify)(void *remote, void *local, struct lob_struct *outer); struct lob_struct *(*remote_encrypt)(void *remote, void *local, struct lob_struct *inner); unsigned char (*remote_validate)(void *remote, struct lob_struct *args, struct lob_struct *sig, unsigned char *data, unsigned long len); void *(*ephemeral_new)(void *remote, struct lob_struct *outer); void (*ephemeral_free)(void *ephemeral); struct lob_struct *(*ephemeral_encrypt)(void *ephemeral, struct lob_struct *inner); struct lob_struct *(*ephemeral_decrypt)(void *ephemeral, struct lob_struct *outer); unsigned char id; char hex[3]; } *cs; struct e3x_self_struct *self; void *remote; void *ephem; unsigned int in; unsigned int cid; unsigned char token[16]; unsigned char csid; char hex[3]; } *x; struct mesh_struct *mesh; struct lob_struct *key; struct chan_struct { struct link_struct *link; struct chan_struct *next; unsigned int id; char *type; struct lob_struct *in; unsigned int tsent; unsigned int timeout; void *arg; void (*handle)(struct chan_struct *c, void *arg); enum chan_states { CHAN_ENDED=0, CHAN_OPENING=1, CHAN_OPEN=2 } state; } *chans; unsigned int state; void *send_arg; struct link_struct *(*send_cb)(struct link_struct *link, struct lob_struct *packet, void *arg); struct link_struct *next; unsigned char csid; } *links; } *a; } *


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

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

original_code:
void net_loopback_free(net_loopback_t pair)
{
  free(pair);
  return;
}

canonical_original_code:
void net_loopback_free(struct net_loopback_struct *pair)
{
  free(pair);
  return;
}


repo: tenchman/gsclu

decompiled_code:
__int64 __fastcall check_cn(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
int v5; // ebx
int v6; // eax

v3 = a2;
if ( *a1 != 42 )
return str_casecmp(a2, a1, a3);
v5 = str_len(a2);
v6 = v5 - str_len(a1 + 1);
if ( v6 >= 0 )
v3 = a2 + v6;
return str_casecmp(v3, a1 + 1, a2 + v6);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
int v5; // ebx
int v6; // eax

v3 = a2;
if ( *a1 != 42 )
return str_casecmp(a2, a1, a3);
v5 = str_len(a2);
v6 = v5 - str_len(a1 + 1);
if ( v6 >= 0 )
v3 = a2 + v6;
return str_casecmp(v3, a1 + 1, a2 + v6);
}

original_code:
int check_cn(char *cn, char *fqdn)
{
  int n;
  if (*cn == '*') {
    cn++;
    n = str_len(fqdn) - str_len(cn);
    if (n >= 0)
      fqdn += n;
  }
  return str_casecmp(fqdn, cn);
}

variable_types:
cn
char *

variable_types:
fqdn
char *

variable_types: n int


rblcheck

original_code:
static char *rblcheck(struct in_addr *in, rbldomain_t * dom)
{
  unsigned char fixedans[512];
  unsigned char *answer = fixedans;
  unsigned char *cp;
  char *result = (char *) 0;
  char domain[dom->len + 17];
  int len, packetsz = 512, type = ns_t_a;
  time_t now = time(((void *)0));
  if (dom->failcount >= 5
      && (now - dom->lastsuccess) < 5 * 60)
    return ((void *)0);
  if (_setjmp (env) == 14) {
    write(2, "timeout querying ", sizeof("timeout querying ") - 1);
    write(2, dom->name, dom->len);
    write(2, "\n", sizeof("\n") - 1);
    dom->failcount++;
    return ((void *)0);
  }
  strcpy(domain, (const char *) inet_ntoa(*in));
  strncat(domain, ".", 1);
  strncat(domain, dom->name, dom->len);
tryagain:
  alarm(15);
  len = __res_query(domain, ns_c_in, type, answer, packetsz);
  alarm(0);
  dom->lastsuccess = now;
  dom->failcount = 0;
  if (len == -1)
    return result;
  if (len > packetsz) {
    answer = malloc(len);
    packetsz = len;
    goto tryagain;
  }
  if (type == ns_t_a) {
    result = malloc(0xFE + 1);
    result[0] = result[0xFE] = '\0';
    type = ns_t_txt;
    goto tryagain;
  }
  cp = answer + sizeof(HEADER);
  cp += __dn_skipname(cp, answer + len);
  cp += 2 + 2;
  cp += __dn_skipname(cp, answer + len);
  cp += 2 + 2 + 4;
  do { const unsigned char *t_cp = (const unsigned char *)(cp); (len) = ((uint16_t)t_cp[0] << 8) | ((uint16_t)t_cp[1]) ; (cp) += 2; } while (0);
  if (len) {
    if ((len = (int) *cp++) > 0xFE)
      len = 0xFE;
    strncpy(result, (char *) cp, len);
    result[len] = '\0';
  }
  if (answer != fixedans)
    free(answer);
  return result;
}

canonical_original_code:
static char *rblcheck(struct in_addr *in, struct rbldomain_t *dom)
{
  unsigned char fixedans[512];
  unsigned char *answer = fixedans;
  unsigned char *cp;
  char *result = (char *) 0;
  char domain[-1];
  int len; int packetsz = 512; int type = ns_t_a;
  long now = time(((void *)0));
  if (dom->failcount >= 5
      && (now - dom->lastsuccess) < 5 * 60)
    return ((void *)0);
  if (_setjmp (env) == 14) {
    write(2, "timeout querying ", sizeof("timeout querying ") - 1);
    write(2, dom->name, dom->len);
    write(2, "\n", sizeof("\n") - 1);
    dom->failcount++;
    return ((void *)0);
  }
  strcpy(domain, (char *) inet_ntoa(*in));
  strncat(domain, ".", 1);
  strncat(domain, dom->name, dom->len);
tryagain:
  alarm(15);
  len = __res_query(domain, ns_c_in, type, answer, packetsz);
  alarm(0);
  dom->lastsuccess = now;
  dom->failcount = 0;
  if (len == -1)
    return result;
  if (len > packetsz) {
    answer = malloc(len);
    packetsz = len;
    goto tryagain;
  }
  if (type == ns_t_a) {
    result = malloc(0xFE + 1);
    result[0] = result[0xFE] = '\0';
    type = ns_t_txt;
    goto tryagain;
  }
  cp = answer + sizeof(HEADER);
  cp += __dn_skipname(cp, answer + len);
  cp += 2 + 2;
  cp += __dn_skipname(cp, answer + len);
  cp += 2 + 2 + 4;
  do { unsigned char *t_cp = (const unsigned char *)(cp); (len) = ((unsigned short)t_cp[0] << 8) | ((unsigned short)t_cp[1]) ; (cp) += 2; } while (0);
  if (len) {
    if ((len = (int) *cp++) > 0xFE)
      len = 0xFE;
    strncpy(result, (char *) cp, len);
    result[len] = '\0';
  }
  if (answer != fixedans)
    free(answer);
  return result;
}

variable_types: struct in_addr { unsigned int s_addr; } *

variable_types: struct rbldomain_t { unsigned char failcount; long lastsuccess; unsigned long len; char name[]; } *

variable_types:
fixedans
unsigned char [512]

variable_types:
answer
unsigned char *

variable_types:
cp
unsigned char *

variable_types:
result
char *

variable_types:
domain
char [-1]

variable_types: len int

variable_types: packetsz int

variable_types: type int

variable_types: now long

return_type: char *


sigalarm

decompiled_code:
void __fastcall __noreturn sigalarm(int a1)
{
longjmp(env, a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(int a1)
{
longjmp(env, a1);
}

original_code:
static void sigalarm(int signal)
{
  longjmp(env, signal);
}

variable_types: signal int


decompiled_code:
__int64 __fastcall read_rbldomains(__int64 a1)
{
unsigned __int64 v1; // rax
size_t v2; // rsi
char *v3; // r12
const char *v4; // r13
const char *v5; // r14
char *v6; // rbp
size_t v7; // r15
const char *v8; // rbx
char *v9; // rbp
time_t v10; // rax
char *v11; // rdi
char v12; // al
void *v13; // rax
void *v14; // rax
char v17[48]; // [rsp+10h] [rbp-4C8h] BYREF
size_t len; // [rsp+40h] [rbp-498h]
__int64 v19; // [rsp+68h] [rbp-470h]
char src[1080]; // [rsp+A0h] [rbp-438h] BYREF

v1 = mmapfile(*(_QWORD *)a1, v17);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = len;
v3 = (char *)v1;
v4 = (const char *)(v1 + len);
if ( v1 >= v1 + len )
{
LABEL_14:
*(_QWORD *)(a1 + 32) = v19;
munmap(v3, v2);
return 0LL;
}
v5 = (const char *)v1;
v6 = src;
while ( 1 )
{
v7 = strcspn(v5, "\r\n");
v8 = &v5[v7];
if ( !v7 )
{
v8 = v4;
v7 = v4 - v5;
}
*v6 = 0;
v9 = v6 + 24;
v10 = time(0LL);
*((_QWORD *)v9 - 1) = v7;
*((_QWORD *)v9 - 2) = v10;
v11 = v9;
v6 = &v9[v7];
strncpy(v11, v5, v7);
if ( *v8 == 13 || *v8 == 10 )
{
do
{
do
v12 = *++v8;
while ( v12 == 10 );
}
while ( v12 == 13 );
}
v4 = &v3[len];
if ( &v3[len] <= v8 )
break;
v5 = v8;
}
v13 = realloc(*(void **)(a1 + 24), v6 - src);
if ( v13 )
{
v14 = memcpy(v13, src, v6 - src);
v2 = len;
*(_QWORD *)(a1 + 24) = v14;
goto LABEL_14;
}
munmap(v3, len);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned __int64 v1; // rax
size_t v2; // rsi
char *v3; // r12
const char *v4; // r13
const char *v5; // r14
char *v6; // rbp
size_t v7; // r15
const char *v8; // rbx
char *v9; // rbp
time_t v10; // rax
char *v11; // rdi
char v12; // al
void *v13; // rax
void *v14; // rax
char v17[48]; // [rsp+10h] [rbp-4C8h] BYREF
size_t len; // [rsp+40h] [rbp-498h]
__int64 v19; // [rsp+68h] [rbp-470h]
char src[1080]; // [rsp+A0h] [rbp-438h] BYREF

v1 = mmapfile(*(_QWORD *)a1, v17);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = len;
v3 = (char *)v1;
v4 = (const char *)(v1 + len);
if ( v1 >= v1 + len )
{
LABEL_14:
*(_QWORD *)(a1 + 32) = v19;
munmap(v3, v2);
return 0LL;
}
v5 = (const char *)v1;
v6 = src;
while ( 1 )
{
v7 = strcspn(v5, "\r\n");
v8 = &v5[v7];
if ( !v7 )
{
v8 = v4;
v7 = v4 - v5;
}
*v6 = 0;
v9 = v6 + 24;
v10 = time(0LL);
*((_QWORD *)v9 - 1) = v7;
*((_QWORD *)v9 - 2) = v10;
v11 = v9;
v6 = &v9[v7];
strncpy(v11, v5, v7);
if ( *v8 == 13 || *v8 == 10 )
{
do
{
do
v12 = *++v8;
while ( v12 == 10 );
}
while ( v12 == 13 );
}
v4 = &v3[len];
if ( &v3[len] <= v8 )
break;
v5 = v8;
}
v13 = realloc(*(void **)(a1 + 24), v6 - src);
if ( v13 )
{
v14 = memcpy(v13, src, v6 - src);
v2 = len;
*(_QWORD *)(a1 + 24) = v14;
goto LABEL_14;
}
munmap(v3, len);
return 0xFFFFFFFFLL;
}

original_code:
static int read_rbldomains(config_t * c)
{
  char dombuf[1024];
  rbldomain_t *dom = ((void *)0);
  char *dombufpos = dombuf;
  char *buf, *tmp;
  struct stat st;
  if ((buf = tmp = mmapfile(c->domaincfg, &st)) == ((void *)0))
    return -1;
  while (tmp < buf + st.st_size) {
    size_t n = strcspn(tmp, "\r\n");
    if (!n)
      n = buf + st.st_size - tmp;
    dom = (rbldomain_t *) dombufpos;
    dom->failcount = 0;
    dom->lastsuccess = time(((void *)0));
    dom->len = n;
    strncpy(dom->name, tmp, n);
    dombufpos = dom->name + n;
    tmp += n;
    while (*tmp == '\n' || *tmp == '\r')
      ++tmp;
  }
  if (dom) {
    char *r = realloc(c->rbldomains, dombufpos - dombuf);
    if (!r) {
      munmap(buf, st.st_size);
      return -1;
    }
    memcpy(r, dombuf, dombufpos - dombuf);
    c->rbldomains = r;
  }
  c->timestamp = st.st_mtim.tv_sec;
  munmap(buf, st.st_size);
  return 0;
}

canonical_original_code:
static int read_rbldomains(struct config_t *c)
{
  char dombuf[1024];
  struct rbldomain_t *dom = ((void *)0);
  char *dombufpos = dombuf;
  char *buf; char *tmp;
  struct stat st;
  if ((buf = tmp = mmapfile(c->domaincfg, &st)) == ((void *)0))
    return -1;
  while (tmp < buf + st.st_size) {
    unsigned long n = strcspn(tmp, "\r\n");
    if (!n)
      n = buf + st.st_size - tmp;
    dom = (struct rbldomain_t *) dombufpos;
    dom->failcount = 0;
    dom->lastsuccess = time(((void *)0));
    dom->len = n;
    strncpy(dom->name, tmp, n);
    dombufpos = dom->name + n;
    tmp += n;
    while (*tmp == '\n' || *tmp == '\r')
      ++tmp;
  }
  if (dom) {
    char *r = realloc(c->rbldomains, dombufpos - dombuf);
    if (!r) {
      munmap(buf, st.st_size);
      return -1;
    }
    memcpy(r, dombuf, dombufpos - dombuf);
    c->rbldomains = r;
  }
  c->timestamp = st.st_mtim.tv_sec;
  munmap(buf, st.st_size);
  return 0;
}

variable_types: struct config_t { char *domaincfg; char *socketpath; char *pidfile; void *rbldomains; long timestamp; int clientfd; int serverfd; } *

variable_types:
dombuf
char [1024]

variable_types:
dombufpos
char *

variable_types:
buf
char *

variable_types:
tmp
char *

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

variable_types:
n
unsigned long

variable_types:
r
char *

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]; }

user_defined_types: struct rbldomain_t { unsigned char failcount; long lastsuccess; unsigned long len; char name[]; }


decompiled_code:
ssize_t __fastcall write_errno(void *buf)
{
int *v1; // rax
char *v2; // rbp
size_t v3; // rax
size_t v4; // rax

v1 = _errno_location();
v2 = strerror(*v1);
v3 = strlen((const char *)buf);
write(2, buf, v3);
write(2, &unk_43B, 2uLL);
v4 = strlen(v2);
write(2, v2, v4);
return write(2, &unk_1B, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func5(void *buf)
{
int *v1; // rax
char *v2; // rbp
size_t v3; // rax
size_t v4; // rax

v1 = _errno_location();
v2 = strerror(*v1);
v3 = strlen((const char *)buf);
write(2, buf, v3);
write(2, &unk_43B, 2uLL);
v4 = strlen(v2);
write(2, v2, v4);
return write(2, &unk_1B, 1uLL);
}

original_code:
static void write_errno(char *msg)
{
  char *err = strerror((*__errno_location ()));
  write(2, msg, strlen(msg));
  write(2, ": ", 2);
  write(2, err, strlen(err));
  write(2, "\n", 1);
}

variable_types:
msg
char *

variable_types:
err
char *


decompiled_code:
void __fastcall __noreturn die_errno(void *a1)
{
write_errno(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(void *a1)
{
func5(a1);
exit(1);
}

original_code:
static void die_errno(char *msg)
{
  write_errno(msg);
  exit(1);
}


query

original_code:
int query(struct in_addr *in, config_t * c)
{
  char *ptr = c->rbldomains;
  rbldomain_t *dom = (rbldomain_t *) ptr;
  pid_t child;
  while (*dom->name) {
    pid_t pid = fork();
    switch (pid) {
    case -1:
      break;
    case 0:{
 char *result;
 if ((result = rblcheck(in, dom))) {
   char outbuf[strlen(result) + 4 + dom->len];
   strcpy(outbuf, dom->name);
   strcat(outbuf, ": ");
   strcat(outbuf, result);
   strcat(outbuf, "\n");
   write(c->clientfd, outbuf, sizeof(outbuf));
 }
      }
      exit(0);
    default:
      ;
    }
    ptr += sizeof(rbldomain_t) + dom->len;
    dom = (rbldomain_t *) ptr;
  };
  do {
    child = waitpid(-1, ((void *)0), 0);
  } while (child != -1);
  return 0;
}

canonical_original_code:
int query(struct in_addr *in, struct config_t *c)
{
  char *ptr = c->rbldomains;
  struct rbldomain_t *dom = (rbldomain_t *) ptr;
  int child;
  while (*dom->name) {
    int pid = fork();
    switch (pid) {
    case -1:
      break;
    case 0:{
 char *result;
 if ((result = rblcheck(in, dom))) {
   char outbuf[-1];
   strcpy(outbuf, dom->name);
   strcat(outbuf, ": ");
   strcat(outbuf, result);
   strcat(outbuf, "\n");
   write(c->clientfd, outbuf, sizeof(outbuf));
 }
      }
      exit(0);
    default:
      ;
    }
    ptr += sizeof(rbldomain_t) + dom->len;
    dom = (struct rbldomain_t *) ptr;
  };
  do {
    child = waitpid(-1, ((void *)0), 0);
  } while (child != -1);
  return 0;
}

variable_types: struct in_addr { unsigned int s_addr; } *

variable_types:
ptr
char *

variable_types: struct rbldomain_t { unsigned char failcount; long lastsuccess; unsigned long len; char name[]; } *

variable_types: child int

variable_types: pid int

variable_types:
result
char *

variable_types:
outbuf
char [-1]

user_defined_types: struct config_t { char *domaincfg; char *socketpath; char *pidfile; void *rbldomains; long timestamp; int clientfd; int serverfd; }


listener

decompiled_code:
__pid_t __fastcall listener(__int64 a1)
{
struct __res_state *v1; // rax
const char *v2; // rsi
int v3; // eax
int v4; // er12
int v5; // er13
__pid_t result; // eax
int v7; // ebp
struct in_addr inp; // [rsp+4h] [rbp-224h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-220h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-218h] BYREF
int v11; // [rsp+78h] [rbp-1B0h]
__int16 v12; // [rsp+7Ch] [rbp-1ACh]
struct stat v13; // [rsp+80h] [rbp-1A8h] BYREF
char buf[280]; // [rsp+110h] [rbp-118h] BYREF

v1 = _res_state();
v1->options &= 0xFFFFFFFFFFFFFFBFLL;
umask(0x49u);
if ( unlink(*(const char **)(a1 + 8)) == -1 && *_errno_location() != 2 )
die_errno("can't unlink /tmp/.rbldsock");
v2 = *(const char **)(a1 + 8);
memset(&addr, 0, 0x68uLL);
addr.sa_family = 1;
v12 = 0;
v11 = 0;
strncpy(addr.sa_data, v2, 0x6CuLL);
v3 = socket(1, 1, 0);
v4 = v3;
if ( v3 == -1 )
die_errno("error creating listener socket");
if ( bind(v3, &addr, 0x6Eu) == -1 )
{
close(v4);
die_errno("can't bind to socket");
}
if ( listen(v4, 10) == -1 )
{
close(v4);
die_errno("can't listen to socket");
}
signal(15, (__sighandler_t)cleanup);
signal(2, (__sighandler_t)cleanup);
signal(14, (__sighandler_t)sigalarm);
signal(17, handler);
signal(13, handler);
*(_DWORD *)(a1 + 44) = v4;
while ( !signaled )
{
if ( stat(*(const char **)a1, &v13) == -1 )
{
write_errno("can't stat /etc/rbldomains");
}
else if ( v13.st_mtim.tv_sec > *(_QWORD *)(a1 + 32) )
{
write(2, "rereading /etc/rbldomains\n", 0x1AuLL);
read_rbldomains(a1);
}
fds.fd = v4;
*(_DWORD *)&fds.events = 1;
poll(&fds, 1uLL, -1);
if ( (fds.revents & 1) != 0 )
{
v5 = accept(v4, 0LL, 0LL);
if ( v5 == -1 )
{
write_errno("accept failed");
}
else
{
result = fork();
if ( result == -1 )
return result;
if ( !result )
{
close(v4);
*(_DWORD *)(a1 + 40) = v5;
if ( (unsigned int)read(v5, buf, 0x100uLL) != -1 )
{
if ( !inet_aton(buf, &inp) )
die("invalid ip address");
inp.s_addr = _bswap_32(inp.s_addr);
v7 = query(&inp, a1);
write(v5, &unk_7BA, 1uLL);
close(v5);
exit(v7);
}
die_errno("can't read from socket");
}
waitpid(result, 0LL, 0);
}
}
}
return 0;
}

canonical_decompiled_code:
__pid_t __fastcall func11(__int64 a1)
{
struct __res_state *v1; // rax
const char *v2; // rsi
int v3; // eax
int v4; // er12
int v5; // er13
__pid_t result; // eax
int v7; // ebp
struct in_addr inp; // [rsp+4h] [rbp-224h] BYREF
struct pollfd fds; // [rsp+8h] [rbp-220h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-218h] BYREF
int v11; // [rsp+78h] [rbp-1B0h]
__int16 v12; // [rsp+7Ch] [rbp-1ACh]
struct stat v13; // [rsp+80h] [rbp-1A8h] BYREF
char buf[280]; // [rsp+110h] [rbp-118h] BYREF

v1 = _res_state();
v1->options &= 0xFFFFFFFFFFFFFFBFLL;
umask(0x49u);
if ( unlink(*(const char **)(a1 + 8)) == -1 && *_errno_location() != 2 )
func6("can't unlink /tmp/.rbldsock");
v2 = *(const char **)(a1 + 8);
memset(&addr, 0, 0x68uLL);
addr.sa_family = 1;
v12 = 0;
v11 = 0;
strncpy(addr.sa_data, v2, 0x6CuLL);
v3 = socket(1, 1, 0);
v4 = v3;
if ( v3 == -1 )
func6("error creating listener socket");
if ( bind(v3, &addr, 0x6Eu) == -1 )
{
close(v4);
func6("can't bind to socket");
}
if ( listen(v4, 10) == -1 )
{
close(v4);
func6("can't listen to socket");
}
signal(15, (__sighandler_t)cleanup);
signal(2, (__sighandler_t)cleanup);
signal(14, (__sighandler_t)sigalarm);
signal(17, handler);
signal(13, handler);
*(_DWORD *)(a1 + 44) = v4;
while ( !signaled )
{
if ( stat(*(const char **)a1, &v13) == -1 )
{
func5("can't stat /etc/rbldomains");
}
else if ( v13.st_mtim.tv_sec > *(_QWORD *)(a1 + 32) )
{
write(2, "rereading /etc/rbldomains\n", 0x1AuLL);
func4(a1);
}
fds.fd = v4;
*(_DWORD *)&fds.events = 1;
poll(&fds, 1uLL, -1);
if ( (fds.revents & 1) != 0 )
{
v5 = accept(v4, 0LL, 0LL);
if ( v5 == -1 )
{
func5("accept failed");
}
else
{
result = fork();
if ( result == -1 )
return result;
if ( !result )
{
close(v4);
*(_DWORD *)(a1 + 40) = v5;
if ( (unsigned int)read(v5, buf, 0x100uLL) != -1 )
{
if ( !inet_aton(buf, &inp) )
func1("invalid ip address");
inp.s_addr = func7(inp.s_addr);
v7 = func10(&inp, a1);
write(v5, &unk_7BA, 1uLL);
close(v5);
exit(v7);
}
func6("can't read from socket");
}
waitpid(result, 0LL, 0);
}
}
}
return 0;
}

original_code:
int listener(config_t * c)
{
  pid_t pid;
  struct sockaddr_un server;
  int sfd, cfd;
  (*__res_state()).options &= ~0x00000040;
  umask(0111);
  if (unlink(c->socketpath) == -1 && (*__errno_location ()) != 2)
    die_errno("can't unlink " "/tmp/.rbldsock");
  memset((char *) &server, 0, sizeof(server));
  server.sun_family = 1;
  strncpy(server.sun_path, c->socketpath, sizeof(server.sun_path));
  if ((sfd = socket(1, SOCK_STREAM, 0)) == -1)
    die_errno("error creating listener socket");
  if (bind(sfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) == -1) {
    close(sfd);
    die_errno("can't bind to socket");
  }
  if (listen(sfd, 10) == -1) {
    close(sfd);
    die_errno("can't listen to socket");
  }
  signal(15, cleanup);
  signal(2, cleanup);
  signal(14, sigalarm);
  signal(17, ((__sighandler_t) 1));
  signal(13, ((__sighandler_t) 1));
  c->serverfd = sfd;
  while (!signaled) {
    struct stat st;
    struct pollfd pfd;
    if (stat(c->domaincfg, &st) == -1) {
      write_errno("can't stat " "/etc/rbldomains");
    } else if (st.st_mtim.tv_sec > c->timestamp) {
      write(2, "rereading " "/etc/rbldomains" "\n", sizeof("rereading " "/etc/rbldomains" "\n") - 1);
      read_rbldomains(c);
    }
    pfd.fd = sfd;
    pfd.events = 0x001;
    pfd.revents = 0;
    poll(&pfd, 1, -1);
    if ((pfd.revents & 0x001) != 0) {
      if ((cfd = accept(sfd, ((void *)0), ((void *)0))) == -1) {
 write_errno("accept failed");
 continue;
      }
      pid = fork();
      switch (pid) {
      case -1:
 return -1;
      case 0:{
   struct in_addr inaddr;
   char buf[256];
   int retval;
   close(sfd);
   c->clientfd = cfd;
   if ((retval = read(cfd, buf, sizeof(buf))) == -1)
     die_errno("can't read from socket");
   if (inet_aton(buf, &inaddr) == 0)
     die("invalid ip address");
   inaddr.s_addr = htonl(inaddr.s_addr);
   retval = query(&inaddr, c);
   write(cfd, "", 1);
   close(cfd);
   exit(retval);
 }
      default:
 waitpid(pid, ((void *)0), 0);
      }
    }
  }
  return 0;
}

canonical_original_code:
int listener(struct config_t *c)
{
  int pid;
  struct sockaddr_un server;
  int sfd; int cfd;
  (*__res_state()).options &= ~0x00000040;
  umask(0111);
  if (unlink(c->socketpath) == -1 && (*__errno_location ()) != 2)
    die_errno("can't unlink " "/tmp/.rbldsock");
  memset((char *) &server, 0, sizeof(server));
  server.sun_family = 1;
  strncpy(server.sun_path, c->socketpath, sizeof(server.sun_path));
  if ((sfd = socket(1, SOCK_STREAM, 0)) == -1)
    die_errno("error creating listener socket");
  if (bind(sfd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) == -1) {
    close(sfd);
    die_errno("can't bind to socket");
  }
  if (listen(sfd, 10) == -1) {
    close(sfd);
    die_errno("can't listen to socket");
  }
  signal(15, cleanup);
  signal(2, cleanup);
  signal(14, sigalarm);
  signal(17, ((void (*)(int)) 1));
  signal(13, ((void (*)(int)) 1));
  c->serverfd = sfd;
  while (!signaled) {
    struct stat st;
    struct pollfd pfd;
    if (stat(c->domaincfg, &st) == -1) {
      write_errno("can't stat " "/etc/rbldomains");
    } else if (st.st_mtim.tv_sec > c->timestamp) {
      write(2, "rereading " "/etc/rbldomains" "\n", sizeof("rereading " "/etc/rbldomains" "\n") - 1);
      read_rbldomains(c);
    }
    pfd.fd = sfd;
    pfd.events = 0x001;
    pfd.revents = 0;
    poll(&pfd, 1, -1);
    if ((pfd.revents & 0x001) != 0) {
      if ((cfd = accept(sfd, ((void *)0), ((void *)0))) == -1) {
 write_errno("accept failed");
 continue;
      }
      pid = fork();
      switch (pid) {
      case -1:
 return -1;
      case 0:{
   struct in_addr inaddr;
   char buf[256];
   int retval;
   close(sfd);
   c->clientfd = cfd;
   if ((retval = read(cfd, buf, sizeof(buf))) == -1)
     die_errno("can't read from socket");
   if (inet_aton(buf, &inaddr) == 0)
     die("invalid ip address");
   inaddr.s_addr = htonl(inaddr.s_addr);
   retval = query(&inaddr, c);
   write(cfd, "", 1);
   close(cfd);
   exit(retval);
 }
      default:
 waitpid(pid, ((void *)0), 0);
      }
    }
  }
  return 0;
}

variable_types: struct config_t { char *domaincfg; char *socketpath; char *pidfile; void *rbldomains; long timestamp; int clientfd; int serverfd; } *

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

variable_types: sfd int

variable_types: cfd int

variable_types: struct pollfd { int fd; short events; short revents; }

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }

variable_types:
buf
char [256]

variable_types: retval int

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

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


cleanup

decompiled_code:
void cleanup()
{
signaled = 1;
}

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

original_code:
static void cleanup(int signal)
{
  signaled = 1;
}

variable_types: signal int


die

decompiled_code:
void __fastcall __noreturn die(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
write(2, buf, v1);
write(2, &unk_1B, 1uLL);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
write(2, buf, v1);
write(2, &unk_1B, 1uLL);
exit(1);
}

original_code:
static void die(char *msg)
{
  write(2, msg, strlen(msg));
  write(2, "\n", 1);
  exit(1);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall fmt_ulong(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned int v3; // er8
unsigned __int64 v4; // rcx
__int64 v5; // rdi
unsigned __int64 v6; // rax

if ( a2 <= 9 )
{
v3 = 1;
}
else
{
v2 = a2;
v3 = 1;
do
{
v4 = v2;
++v3;
v2 /= 0xAuLL;
}
while ( v4 > 0x63 );
}
if ( a1 )
{
v5 = v3 + a1;
do
{
*(_BYTE *)--v5 = a2 % 0xA + 48;
v6 = a2;
a2 /= 0xAuLL;
}
while ( v6 > 9 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
unsigned int v3; // er8
unsigned __int64 v4; // rcx
__int64 v5; // rdi
unsigned __int64 v6; // rax

if ( a2 <= 9 )
{
v3 = 1;
}
else
{
v2 = a2;
v3 = 1;
do
{
v4 = v2;
++v3;
v2 /= 0xAuLL;
}
while ( v4 > 0x63 );
}
if ( a1 )
{
v5 = v3 + a1;
do
{
*(_BYTE *)--v5 = a2 % 0xA + 48;
v6 = a2;
a2 /= 0xAuLL;
}
while ( v6 > 9 );
}
return v3;
}

original_code:
unsigned int fmt_ulong(register char *s, register unsigned long u)
{
  register unsigned int len;
  register unsigned long q;
  len = 1;
  q = u;
  while (q > 9) {
    ++len;
    q /= 10;
  }
  if (s) {
    s += len;
    do {
      *--s = '0' + (u % 10);
      u /= 10;
    } while (u);
  }
  return len;
}

canonical_original_code:
unsigned int fmt_ulong(char *s, unsigned long u)
{
  register unsigned int len;
  register unsigned long q;
  len = 1;
  q = u;
  while (q > 9) {
    ++len;
    q /= 10;
  }
  if (s) {
    s += len;
    do {
      *--s = '0' + (u % 10);
      u /= 10;
    } while (u);
  }
  return len;
}

variable_types:
s
char *

variable_types:
u
unsigned long

variable_types:
len
unsigned int

variable_types:
q
unsigned long

return_type: unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v5; // [rsp+0h] [rbp-38h] BYREF
char *v6; // [rsp+8h] [rbp-30h]
char *name; // [rsp+10h] [rbp-28h]
__int128 v8; // [rsp+18h] [rbp-20h]
int v9; // [rsp+28h] [rbp-10h]
int fd; // [rsp+2Ch] [rbp-Ch]

v9 = 0;
v5 = "/etc/rbldomains";
v6 = "/tmp/.rbldsock";
name = "/var/run/rbld.pid";
fd = -1;
v8 = 0LL;
v3 = writepid_constprop_0_isra_0("/var/run/rbld.pid");
if ( v3 == -1 )
die_errno("can't write pid file");
if ( v3 )
die("I'm already running!");
if ( (unsigned int)read_rbldomains((__int64)&v5) == -1 )
die("can't read /etc/rbldomains");
listener((__int64)&v5);
if ( fd != -1 )
close(fd);
unlink(name);
unlink(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v5; // [rsp+0h] [rbp-38h] BYREF
char *v6; // [rsp+8h] [rbp-30h]
char *name; // [rsp+10h] [rbp-28h]
__int128 v8; // [rsp+18h] [rbp-20h]
int v9; // [rsp+28h] [rbp-10h]
int fd; // [rsp+2Ch] [rbp-Ch]

v9 = 0;
v5 = "/etc/rbldomains";
v6 = "/tmp/.rbldsock";
name = "/var/run/rbld.pid";
fd = -1;
v8 = 0LL;
v3 = func9("/var/run/rbld.pid");
if ( v3 == -1 )
func6("can't write pid file");
if ( v3 )
func1("I'm already running!");
if ( (unsigned int)func4((__int64)&v5) == -1 )
func1("can't read /etc/rbldomains");
func11((__int64)&v5);
if ( fd != -1 )
close(fd);
unlink(name);
unlink(v6);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  config_t config = {
    .domaincfg = "/etc/rbldomains",
    .socketpath = "/tmp/.rbldsock",
    .pidfile = "/var/run/rbld.pid",
    .rbldomains = ((void *)0),
    .serverfd = -1
  };
  switch (writepid(&config)) {
  case -1:
    die_errno("can't write pid file");
  case 0:
    break;
  default:
    die("I'm already running!");
  }
  if (read_rbldomains(&config) == -1)
    die("can't read " "/etc/rbldomains");
  listener(&config);
  if (config.serverfd != -1)
    close(config.serverfd);
  unlink(config.pidfile);
  unlink(config.socketpath);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct config_t config = {
    .domaincfg = "/etc/rbldomains",
    .socketpath = "/tmp/.rbldsock",
    .pidfile = "/var/run/rbld.pid",
    .rbldomains = ((void *)0),
    .serverfd = -1
  };
  switch (writepid(&config)) {
  case -1:
    die_errno("can't write pid file");
  case 0:
    break;
  default:
    die("I'm already running!");
  }
  if (read_rbldomains(&config) == -1)
    die("can't read " "/etc/rbldomains");
  listener(&config);
  if (config.serverfd != -1)
    close(config.serverfd);
  unlink(config.pidfile);
  unlink(config.socketpath);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct config_t { char *domaincfg; char *socketpath; char *pidfile; void *rbldomains; long timestamp; int clientfd; int serverfd; }


decompiled_code:
__int64 __fastcall strbuf_check(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rax
__int64 result; // rax

v2 = 0LL;
if ( a1 )
v2 = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8));
if ( a2 + 1 > v2 )
result = strbuf_realloc();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rax
__int64 result; // rax

v2 = 0LL;
if ( a1 )
v2 = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8));
if ( a2 + 1 > v2 )
result = strbuf_realloc();
else
result = 0LL;
return result;
}

original_code:
size_t strbuf_check(strbuf_t * strbuf, const size_t len)
{
  if ((strbuf?strbuf->total-strbuf->len:0) < len + 1)
    return strbuf_realloc(strbuf, len);
  return 0;
}

canonical_original_code:
unsigned long strbuf_check(struct strbuf_t *strbuf, unsigned long len)
{
  if ((strbuf?strbuf->total-strbuf->len:0) < len + 1)
    return strbuf_realloc(strbuf, len);
  return 0;
}

variable_types: struct strbuf_t { char *s; unsigned int len; unsigned int total; } *

variable_types:
len
unsigned long

return_type: unsigned long


readulonglong

decompiled_code:
__int64 __fastcall readulonglong(char *a1, _QWORD *a2)
{
char v2; // dl
__int64 result; // rax
unsigned __int8 v5; // dl
__int64 v6; // rcx
__int64 v7; // rsi

v2 = *a1;
result = 0LL;
if ( (unsigned __int8)(*a1 - 9) > 1u )
goto LABEL_3;
do
{
do
{
result = (unsigned int)(result + 1);
v2 = a1[result];
}
while ( (unsigned __int8)(v2 - 9) <= 1u );
LABEL_3:
;
}
while ( v2 == 32 );
v5 = v2 - 48;
v6 = 0LL;
v7 = v5;
if ( v5 <= 9u )
{
do
{
v6 = v7 + 10 * v6;
result = (unsigned int)(result + 1);
v7 = (unsigned __int8)(a1[result] - 48);
}
while ( (unsigned __int8)(a1[result] - 48) <= 9u );
}
*a2 = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, _QWORD *a2)
{
char v2; // dl
__int64 result; // rax
unsigned __int8 v5; // dl
__int64 v6; // rcx
__int64 v7; // rsi

v2 = *a1;
result = 0LL;
if ( (unsigned __int8)(*a1 - 9) > 1u )
goto LABEL_3;
do
{
do
{
result = (unsigned int)(result + 1);
v2 = a1[result];
}
while ( (unsigned __int8)(v2 - 9) <= 1u );
LABEL_3:
;
}
while ( v2 == 32 );
v5 = v2 - 48;
v6 = 0LL;
v7 = v5;
if ( v5 <= 9u )
{
do
{
v6 = v7 + 10 * v6;
result = (unsigned int)(result + 1);
v7 = (unsigned __int8)(a1[result] - 48);
}
while ( (unsigned __int8)(a1[result] - 48) <= 9u );
}
*a2 = v6;
return result;
}

original_code:
int readulonglong(char *s, unsigned long long *u)
{
  register unsigned int pos = 0;
  unsigned long long result = 0;
  unsigned long long c;
  while (s[pos] == ' ' || s[pos] == '\n' || s[pos] == '\t')
    ++pos;
  while ((c = (unsigned long long) (unsigned char) (s[pos] - '0')) < 10) {
    result = result * 10 + c;
    ++pos;
  }
  *u = result;
  return pos;
}

variable_types:
u
unsigned long long *

variable_types:
pos
unsigned int

variable_types:
result
unsigned long long

variable_types:
c
unsigned long long


readulong

decompiled_code:
__int64 __fastcall readulong(char *a1)
{
__int64 result; // rax
_QWORD *v2; // r9
__int64 v3; // [rsp+8h] [rbp-8h] BYREF

result = readulonglong(a1, &v3);
*v2 = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
__int64 result; // rax
_QWORD *v2; // r9
__int64 v3; // [rsp+8h] [rbp-8h] BYREF

result = func1(a1, &v3);
*v2 = v3;
return result;
}

original_code:
int readulong(char *s, unsigned long *u)
{
  unsigned long long ull;
  int pos = readulonglong(s, &ull);
  *u = (unsigned long) ull;
  return pos;
}

variable_types:
u
unsigned long *

variable_types:
ull
unsigned long long

variable_types: pos int


readlong

decompiled_code:
char *__fastcall readlong(char *a1)
{
char i; // al
int v2; // eax
__int64 v3; // r9
_QWORD *v4; // r10
_QWORD *v6; // r10
__int64 v7; // [rsp+8h] [rbp-8h] BYREF

for ( i = *a1; i == 32; ++a1 )
i = a1[1];
if ( i == 45 )
{
v2 = readulonglong(++a1, &v7);
*v6 = -v7;
}
else
{
v2 = readulonglong(a1, &v7);
*v4 = v7;
}
return &a1[v2 - v3];
}

original_code:
int readlong(char *s, long *l)
{
  unsigned long long ull;
  int negative = 0, pos;
  char *tmp = s;
  while (*tmp == ' ')
    ++tmp;
  if (*tmp == '-') {
    negative = 1;
    ++tmp;
  }
  pos = readulonglong(tmp, &ull);
  if (negative)
    *l = -(long) ull;
  else
    *l = (long) ull;
  return pos + tmp - s;
}

canonical_original_code:
int readlong(char *s, long *l)
{
  unsigned long long ull;
  int negative = 0; int pos;
  char *tmp = s;
  while (*tmp == ' ')
    ++tmp;
  if (*tmp == '-') {
    negative = 1;
    ++tmp;
  }
  pos = readulonglong(tmp, &ull);
  if (negative)
    *l = -(long) ull;
  else
    *l = (long) ull;
  return pos + tmp - s;
}

variable_types:
l
long *

variable_types: negative int

variable_types:
tmp
char *


readint

decompiled_code:
char *__fastcall readint(char *a1)
{
char *result; // rax
_DWORD *v2; // r11
int v3; // [rsp+8h] [rbp-8h]

result = readlong(a1);
*v2 = v3;
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *a1)
{
char *result; // rax
_DWORD *v2; // r11
int v3; // [rsp+8h] [rbp-8h]

result = func3(a1);
*v2 = v3;
return result;
}

original_code:
int readint(char *s, int *i)
{
  long l;
  int pos = readlong(s, &l);
  *i = (int) l;
  return pos;
}

variable_types:
s
char *

variable_types:
i
int *

variable_types: l long


skip

decompiled_code:
__int64 __fastcall skip(char *a1, int a2)
{
char *v2; // rbp
int v3; // ebx
const unsigned __int16 **v4; // rax
char *v5; // rdx
const unsigned __int16 *v6; // rdi
unsigned __int16 v7; // cx
char *v8; // rax
__int16 v9; // si
__int64 v10; // rax

if ( !a2 )
return 0LL;
v2 = a1;
v3 = a2;
v4 = _ctype_b_loc();
v5 = a1;
v6 = *v4;
v7 = (*v4)[*v2];
do
{
v8 = v5;
do
{
v5 = v8++;
v9 = v7 & 0x2000;
v7 = v6[*v8];
}
while ( v9 );
do
{
v10 = *++v5;
v7 = v6[v10];
}
while ( (v7 & 0x2000) == 0 );
--v3;
}
while ( v3 );
return (unsigned int)((_DWORD)v5 - (_DWORD)v2);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, int a2)
{
char *v2; // rbp
int v3; // ebx
const unsigned __int16 **v4; // rax
char *v5; // rdx
const unsigned __int16 *v6; // rdi
unsigned __int16 v7; // cx
char *v8; // rax
__int16 v9; // si
__int64 v10; // rax

if ( !a2 )
return 0LL;
v2 = a1;
v3 = a2;
v4 = _ctype_b_loc();
v5 = a1;
v6 = *v4;
v7 = (*v4)[*v2];
do
{
v8 = v5;
do
{
v5 = v8++;
v9 = v7 & 0x2000;
v7 = v6[*v8];
}
while ( v9 );
do
{
v10 = *++v5;
v7 = v6[v10];
}
while ( (v7 & 0x2000) == 0 );
--v3;
}
while ( v3 );
return (unsigned int)((_DWORD)v5 - (_DWORD)v2);
}

original_code:
int skip(char *s, int n)
{
  char *pos = s;
  while (n) {
    while (((*__ctype_b_loc ())[(int) ((*pos))] & (unsigned short int) _ISspace))
      ++pos;
    while (!((*__ctype_b_loc ())[(int) ((*pos))] & (unsigned short int) _ISspace))
      ++pos;
    --n;
  }
  return pos - s;
}

canonical_original_code:
int skip(char *s, int n)
{
  char *pos = s;
  while (n) {
    while (((*__ctype_b_loc ())[(int) ((*pos))] & (unsigned short) _ISspace))
      ++pos;
    while (!((*__ctype_b_loc ())[(int) ((*pos))] & (unsigned short) _ISspace))
      ++pos;
    --n;
  }
  return pos - s;
}

variable_types: n int

variable_types:
pos
char *