decompiled_code:
unsigned __int64 __fastcall base32_encode(unsigned __int8 *a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v9; // rbx
int v10; // esi
int v11; // edi
int v12; // ecx
int v13; // edx

if ( !a1 || !a3 || !a4 || !a2 )
return 0LL;
result = 0LL;
v9 = 1LL;
v10 = *a1;
v11 = 8;
while ( 1 )
{
v12 = v11 - 5;
++result;
*(_BYTE *)(a3 + result - 1) = byte_270[(v10 >> (v11 - 5)) & 0x1F];
if ( a4 <= result )
break;
if ( v12 <= 0 && v9 >= a2 )
{
*(_BYTE *)(a3 + result) = 0;
return result;
}
if ( v12 > 4 )
{
v11 -= 5;
}
else if ( v9 >= a2 )
{
v11 = 5;
v10 <<= 5 - v12;
}
else
{
v13 = a1[v9];
v11 += 3;
++v9;
v10 = v13 | (v10 << 8);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int8 *a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4)
{
unsigned __int64 result; // rax
unsigned __int64 v9; // rbx
int v10; // esi
int v11; // edi
int v12; // ecx
int v13; // edx

if ( !a1 || !a3 || !a4 || !a2 )
return 0LL;
result = 0LL;
v9 = 1LL;
v10 = *a1;
v11 = 8;
while ( 1 )
{
v12 = v11 - 5;
++result;
*(_BYTE *)(a3 + result - 1) = byte_270[(v10 >> (v11 - 5)) & 0x1F];
if ( a4 <= result )
break;
if ( v12 <= 0 && v9 >= a2 )
{
*(_BYTE *)(a3 + result) = 0;
return result;
}
if ( v12 > 4 )
{
v11 -= 5;
}
else if ( v9 >= a2 )
{
v11 = 5;
v10 <<= 5 - v12;
}
else
{
v13 = a1[v9];
v11 += 3;
++v9;
v10 = v13 | (v10 << 8);
}
}
return result;
}

original_code:
size_t base32_encode(const uint8_t *data, size_t length, char *result, size_t bufSize) {
  if (!data || !result || !bufSize || !length) return 0;
  size_t count = 0;
  if (length > 0) {
    int buffer = data[0];
    size_t next = 1;
    int bitsLeft = 8;
    while (count < bufSize && (bitsLeft > 0 || next < length)) {
      if (bitsLeft < 5) {
        if (next < length) {
          buffer <<= 8;
          buffer |= data[next++] & 0xFF;
          bitsLeft += 8;
        } else {
          int pad = 5 - bitsLeft;
          buffer <<= pad;
          bitsLeft += pad;
        }
      }
      int index = 0x1F & (buffer >> (bitsLeft - 5));
      bitsLeft -= 5;
      result[count++] = "abcdefghijklmnopqrstuvwxyz234567"[index];
    }
  }
  if (count < bufSize) {
    result[count] = '\000';
  }
  return count;
}

canonical_original_code:
unsigned long base32_encode(unsigned char *data, unsigned long length, char *result, unsigned long bufSize) {
  if (!data || !result || !bufSize || !length) return 0;
  unsigned long count = 0;
  if (length > 0) {
    int buffer = data[0];
    unsigned long next = 1;
    int bitsLeft = 8;
    while (count < bufSize && (bitsLeft > 0 || next < length)) {
      if (bitsLeft < 5) {
        if (next < length) {
          buffer <<= 8;
          buffer |= data[next++] & 0xFF;
          bitsLeft += 8;
        } else {
          int pad = 5 - bitsLeft;
          buffer <<= pad;
          bitsLeft += pad;
        }
      }
      int index = 0x1F & (buffer >> (bitsLeft - 5));
      bitsLeft -= 5;
      result[count++] = "abcdefghijklmnopqrstuvwxyz234567"[index];
    }
  }
  if (count < bufSize) {
    result[count] = '\000';
  }
  return count;
}

variable_types:
result
char *

variable_types:
next
unsigned long

variable_types: bitsLeft int

variable_types: pad int

variable_types: index int


repo: telehash/telehash-c

decompiled_code:
unsigned __int64 __fastcall base32_encode_length(__int64 a1)
{
return 8 * a1 / 5uLL + (0xCCCCCCCCCCCCCCCDLL * a1 > 0x3333333333333333LL) + 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1)
{
return 8 * a1 / 5uLL + (0xCCCCCCCCCCCCCCCDLL * a1 > 0x3333333333333333LL) + 1;
}

original_code:
size_t base32_encode_length(size_t rawLength)
{
  return ((rawLength * 8) / 5) + ((rawLength % 5) != 0) + 1;
}

canonical_original_code:
unsigned long base32_encode_length(unsigned long rawLength)
{
  return ((rawLength * 8) / 5) + ((rawLength % 5) != 0) + 1;
}

variable_types:
rawLength
unsigned long

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall base32_decode_floor(__int64 a1)
{
return (unsigned __int64)(5 * a1) >> 3;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
return (unsigned __int64)(5 * a1) >> 3;
}

original_code:
size_t base32_decode_floor(size_t base32Length)
{
  return ((base32Length * 5) / 8);
}

canonical_original_code:
unsigned long base32_decode_floor(unsigned long base32Length)
{
  return ((base32Length * 5) / 8);
}


decompiled_code:
__int64 __fastcall util_chunk_new(__int64 a1, unsigned __int8 a2)
{
_BYTE *v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = calloc(a2 + 16LL, 1uLL);
if ( !v2 )
return ((__int64 (__fastcall *)(__int64, const char *, __int64, const char *, void *))util_sys_log)(
7LL,
"src/util/chunks.c",
12LL,
"util_chunk_new",
&unk_8C8);
v3 = *(_QWORD *)a1;
v2[8] = a2;
*(_QWORD *)a1 = v2;
*(_QWORD *)v2 = v3;
result = a1;
*(_BYTE *)(a1 + 27) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2)
{
_BYTE *v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = calloc(a2 + 16LL, 1uLL);
if ( !v2 )
return ((__int64 (__fastcall *)(__int64, const char *, __int64, const char *, void *))util_sys_log)(
7LL,
"src/util/chunks.c",
12LL,
"util_chunk_new",
&unk_8C8);
v3 = *(_QWORD *)a1;
v2[8] = a2;
*(_QWORD *)a1 = v2;
*(_QWORD *)v2 = v3;
result = a1;
*(_BYTE *)(a1 + 27) = 0;
return result;
}

original_code:
util_chunks_t util_chunk_new(util_chunks_t chunks, uint8_t len)
{
  util_chunk_t chunk;
  size_t size = sizeof (struct util_chunk_struct);
  size += len;
  if(!(chunk = malloc(size))) return util_sys_log(7, "src/util/chunks.c", 12, __func__, "OOM");
  memset(chunk,0,size);
  chunk->size = len;
  chunk->prev = chunks->reading;
  chunks->reading = chunk;
  chunks->readat = 0;
  return chunks;
}

canonical_original_code:
struct util_chunks_struct *util_chunk_new(struct util_chunks_struct *chunks, unsigned char len)
{
  struct util_chunk_struct *chunk;
  unsigned long size = sizeof (struct util_chunk_struct);
  size += len;
  if(!(chunk = malloc(size))) return util_sys_log(7, "src/util/chunks.c", 12, __func__, "OOM");
  memset(chunk,0,size);
  chunk->size = len;
  chunk->prev = chunks->reading;
  chunks->reading = chunk;
  chunks->readat = 0;
  return chunks;
}

variable_types:
chunks
struct util_chunks_struct *

variable_types:
len
unsigned char

variable_types:
size
unsigned long

return_type: struct util_chunks_struct { struct util_chunk_struct { struct util_chunk_struct *prev; unsigned char size; unsigned char data[]; } *reading; 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; } *writing; unsigned long writeat; unsigned short waitat; unsigned char waiting; unsigned char readat; unsigned char cap; unsigned char blocked; } *

user_defined_types: struct util_chunks_struct { struct util_chunk_struct *reading; struct lob_struct *writing; unsigned long writeat; unsigned short waitat; unsigned char waiting; unsigned char readat; unsigned char cap; unsigned char blocked; }


decompiled_code:
__int64 __fastcall util_chunk_free(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
_QWORD *v1; // rbx
void *v2; // rdi

if ( !ptr )
return 0LL;
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
return 0LL;
}

original_code:
util_chunk_t util_chunk_free(util_chunk_t chunk)
{
  if(!chunk) return ((void *)0);
  util_chunk_t prev = chunk->prev;
  free(chunk);
  return util_chunk_free(prev);
}

canonical_original_code:
struct util_chunk_struct *util_chunk_free(struct util_chunk_struct *chunk)
{
  if(!chunk) return ((void *)0);
  struct util_chunk_struct *prev = chunk->prev;
  free(chunk);
  return util_chunk_free(prev);
}

variable_types:
chunk
struct util_chunk_struct *

variable_types: struct util_chunk_struct { struct util_chunk_struct *prev; unsigned char size; unsigned char data[]; } *


decompiled_code:
__int64 __fastcall util_chunks_free(void *ptr)
{
if ( !ptr )
return 0LL;
if ( *((_QWORD *)ptr + 1) )
lob_free();
util_chunk_free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
if ( !ptr )
return 0LL;
if ( *((_QWORD *)ptr + 1) )
lob_free();
func1(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
util_chunks_t util_chunks_free(util_chunks_t chunks)
{
  if(!chunks) return ((void *)0);
  if(chunks->writing) lob_free(chunks->writing);
  util_chunk_free(chunks->reading);
  free(chunks);
  return ((void *)0);
}

canonical_original_code:
struct util_chunks_struct *util_chunks_free(struct util_chunks_struct *chunks)
{
  if(!chunks) return ((void *)0);
  if(chunks->writing) lob_free(chunks->writing);
  util_chunk_free(chunks->reading);
  free(chunks);
  return ((void *)0);
}

user_defined_types: struct util_chunk_struct { struct util_chunk_struct *prev; unsigned char size; unsigned char data[]; }

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


decompiled_code:
__int64 __fastcall util_chunks_send(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
if ( !a1 || !a2 )
return util_sys_log(7LL, "src/util/chunks.c", 76LL, "util_chunks_send", "bad args", a6);
*(_QWORD *)(a1 + 8) = lob_push(*(_QWORD *)(a1 + 8));
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
if ( !a1 || !a2 )
return util_sys_log(7LL, "src/util/chunks.c", 76LL, "util_chunks_send", "bad args", a6);
*(_QWORD *)(a1 + 8) = lob_push(*(_QWORD *)(a1 + 8));
return a1;
}

original_code:
util_chunks_t util_chunks_send(util_chunks_t chunks, lob_t out)
{
  if(!chunks || !out) return util_sys_log(7, "src/util/chunks.c", 76, __func__, "bad args");
  chunks->writing = lob_push(chunks->writing, out);
  return chunks;
}

canonical_original_code:
struct util_chunks_struct *util_chunks_send(struct util_chunks_struct *chunks, struct lob_struct *out)
{
  if(!chunks || !out) return util_sys_log(7, "src/util/chunks.c", 76, __func__, "bad args");
  chunks->writing = lob_push(chunks->writing, out);
  return chunks;
}

variable_types:
out
struct lob_struct *


original_code:
lob_t util_chunks_receive(util_chunks_t chunks)
{
  util_chunk_t chunk, flush;
  size_t len = 0;
  if(!chunks || !chunks->reading) return ((void *)0);
  for(flush = ((void *)0),chunk = chunks->reading;chunk;chunk=chunk->prev)
  {
    if(chunk->size == 0)
    {
      flush = chunk;
      len = 0;
    }
    if(flush) len += chunk->size;
  }
  if(!flush) return ((void *)0);
  if(chunks->reading == flush)
  {
    chunks->reading = ((void *)0);
  }else{
    for(chunk = chunks->reading;chunk->prev != flush;chunk = chunk->prev);
    chunk->prev = ((void *)0);
  }
  chunk = flush->prev;
  free(flush);
  if(!chunk) return util_chunks_receive(chunks);
  uint8_t *buf = malloc(len);
  if(!buf) return util_sys_log(7, "src/util/chunks.c", 124, __func__, "OOM");
  util_chunk_t prev;
  size_t at;
  for(at=len;chunk;chunk = prev)
  {
    prev = chunk->prev;
    memcpy(buf+(at-chunk->size),chunk->data,chunk->size);
    at -= chunk->size;
    free(chunk);
  }
  chunks->ack = 1;
  lob_t ret = lob_parse(buf,len);
  chunks->err = ret ? 0 : 1;
  free(buf);
  return ret;
}

canonical_original_code:
struct lob_struct *util_chunks_receive(struct util_chunks_struct *chunks)
{
  struct util_chunk_struct *chunk; struct util_chunk_struct *flush;
  unsigned long len = 0;
  if(!chunks || !chunks->reading) return ((void *)0);
  for(flush = ((void *)0),chunk = chunks->reading;chunk;chunk=chunk->prev)
  {
    if(chunk->size == 0)
    {
      flush = chunk;
      len = 0;
    }
    if(flush) len += chunk->size;
  }
  if(!flush) return ((void *)0);
  if(chunks->reading == flush)
  {
    chunks->reading = ((void *)0);
  }else{
    for(chunk = chunks->reading;chunk->prev != flush;chunk = chunk->prev);
    chunk->prev = ((void *)0);
  }
  chunk = flush->prev;
  free(flush);
  if(!chunk) return util_chunks_receive(chunks);
  unsigned char *buf = malloc(len);
  if(!buf) return util_sys_log(7, "src/util/chunks.c", 124, __func__, "OOM");
  struct util_chunk_struct *prev;
  unsigned long at;
  for(at=len;chunk;chunk = prev)
  {
    prev = chunk->prev;
    memcpy(buf+(at-chunk->size),chunk->data,chunk->size);
    at -= chunk->size;
    free(chunk);
  }
  chunks->ack = 1;
  struct lob_struct *ret = lob_parse(buf,len);
  chunks->err = ret ? 0 : 1;
  free(buf);
  return ret;
}

variable_types: struct util_chunks_struct { struct util_chunk_struct { struct util_chunk_struct *prev; unsigned char size; unsigned char data[]; } *reading; struct lob_struct *writing; unsigned long writeat; unsigned short waitat; unsigned char waiting; unsigned char readat; unsigned char cap; unsigned char blocked; } *

variable_types:
len
unsigned long

variable_types:
buf
unsigned char *

variable_types:
at
unsigned long

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


decompiled_code:
__int64 __fastcall util_chunks_len(__int64 a1)
{
char v1; // dl
__int64 result; // rax
__int64 v3; // rax
int v4; // edx
unsigned __int64 v5; // rax

if ( !a1 )
return 0LL;
v1 = *(_BYTE *)(a1 + 29);
result = 0LL;
if ( (v1 & 1) == 0 )
{
if ( *(_QWORD *)(a1 + 8) )
{
v3 = lob_len();
if ( !*(_BYTE *)(a1 + 26) )
{
v5 = v3 - *(_QWORD *)(a1 + 16);
if ( *(unsigned __int8 *)(a1 + 28) <= v5 )
LOBYTE(v5) = *(_BYTE *)(a1 + 28);
*(_BYTE *)(a1 + 26) = v5;
}
v4 = *(unsigned __int16 *)(a1 + 24);
result = 1LL;
if ( (_WORD)v4 )
result = (unsigned int)*(unsigned __int8 *)(a1 + 26) - (v4 - 1);
}
else
{
result = (v1 & 4) != 0;
}
}
return result;
}

original_code:
uint32_t util_chunks_len(util_chunks_t chunks)
{
  if(!chunks || chunks->blocked) return 0;
  if(!chunks->writing) return (chunks->ack) ? 1 : 0;
  size_t avail = lob_len(chunks->writing) - chunks->writeat;
  if(avail > chunks->cap) avail = chunks->cap;
  if(!chunks->waiting) chunks->waiting = avail;
  if(!chunks->waitat) return 1;
  return chunks->waiting - (chunks->waitat-1);
}

canonical_original_code:
unsigned int util_chunks_len(struct util_chunks_struct *chunks)
{
  if(!chunks || chunks->blocked) return 0;
  if(!chunks->writing) return (chunks->ack) ? 1 : 0;
  unsigned long avail = lob_len(chunks->writing) - chunks->writeat;
  if(avail > chunks->cap) avail = chunks->cap;
  if(!chunks->waiting) chunks->waiting = avail;
  if(!chunks->waitat) return 1;
  return chunks->waiting - (chunks->waitat-1);
}

variable_types: struct util_chunks_struct { struct util_chunk_struct { struct util_chunk_struct *prev; unsigned char size; unsigned char data[]; } *reading; 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; } *writing; unsigned long writeat; unsigned short waitat; unsigned char waiting; unsigned char readat; unsigned char cap; unsigned char blocked; } *

variable_types:
avail
unsigned long

return_type: unsigned int


decompiled_code:
__int64 __fastcall util_chunks_writing(__int64 a1)
{
unsigned int v1; // er12
__int64 i; // rbp

v1 = 0;
if ( a1 )
{
util_chunks_len(a1);
v1 = lob_len(*(_QWORD *)(a1 + 8)) - *(_DWORD *)(a1 + 16);
for ( i = lob_next(*(_QWORD *)(a1 + 8)); i; i = lob_next(i) )
v1 += lob_len(i);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // er12
__int64 i; // rbp

v1 = 0;
if ( a1 )
{
func6(a1);
v1 = lob_len(*(_QWORD *)(a1 + 8)) - *(_DWORD *)(a1 + 16);
for ( i = lob_next(*(_QWORD *)(a1 + 8)); i; i = lob_next(i) )
v1 += lob_len(i);
}
return v1;
}

original_code:
uint32_t util_chunks_writing(util_chunks_t chunks)
{
  lob_t cur;
  uint32_t len = 0;
  if(!chunks) return 0;
  util_chunks_len(chunks);
  len = lob_len(chunks->writing) - chunks->writeat;
  for(cur=lob_next(chunks->writing);cur;cur = lob_next(cur)) len += lob_len(cur);
  return len;
}

canonical_original_code:
unsigned int util_chunks_writing(struct util_chunks_struct *chunks)
{
  struct lob_struct *cur;
  unsigned int len = 0;
  if(!chunks) return 0;
  util_chunks_len(chunks);
  len = lob_len(chunks->writing) - chunks->writeat;
  for(cur=lob_next(chunks->writing);cur;cur = lob_next(cur)) len += lob_len(cur);
  return len;
}

variable_types:
len
unsigned int


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

if ( !(unsigned int)util_chunks_len(a1) )
return 0LL;
result = a1 + 26;
if ( *(_WORD *)(a1 + 24) )
result = *(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 24) + lob_raw(*(_QWORD *)(a1 + 8)) - 1;
return result;
}

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

if ( !(unsigned int)func6(a1) )
return 0LL;
result = a1 + 26;
if ( *(_WORD *)(a1 + 24) )
result = *(_QWORD *)(a1 + 16) + *(unsigned __int16 *)(a1 + 24) + lob_raw(*(_QWORD *)(a1 + 8)) - 1;
return result;
}

original_code:
uint8_t *util_chunks_write(util_chunks_t chunks)
{
  if(!util_chunks_len(chunks)) return ((void *)0);
  if(!chunks->waitat) return &chunks->waiting;
  return lob_raw(chunks->writing)+chunks->writeat+(chunks->waitat-1);
}

canonical_original_code:
unsigned char *util_chunks_write(struct util_chunks_struct *chunks)
{
  if(!util_chunks_len(chunks)) return ((void *)0);
  if(!chunks->waitat) return &chunks->waiting;
  return lob_raw(chunks->writing)+chunks->writeat+(chunks->waitat-1);
}

return_type: unsigned char *


original_code:
util_chunks_t util_chunks_written(util_chunks_t chunks, size_t len)
{
  if(!chunks || !len) return chunks;
  if(len > util_chunks_len(chunks)) return util_sys_log(7, "src/util/chunks.c", 216, __func__, "len too big %d > %d",len,util_chunks_len(chunks));
  chunks->waitat += len;
  chunks->ack = 0;
  if(chunks->waitat > chunks->waiting)
  {
    chunks->writeat += chunks->waiting;
    chunks->waiting = chunks->waitat = 0;
    if(chunks->waiting == chunks->cap) chunks->blocked = chunks->blocking;
    if(len == 1 && chunks->writing && chunks->writeat == lob_len(chunks->writing))
    {
      lob_t old = lob_shift(chunks->writing);
      chunks->writing = old->next;
      old->next = ((void *)0);
      lob_free(old);
      chunks->writeat = 0;
      chunks->blocked = chunks->blocking;
    }
  }
  return chunks;
}

canonical_original_code:
struct util_chunks_struct *util_chunks_written(struct util_chunks_struct *chunks, unsigned long len)
{
  if(!chunks || !len) return chunks;
  if(len > util_chunks_len(chunks)) return util_sys_log(7, "src/util/chunks.c", 216, __func__, "len too big %d > %d",len,util_chunks_len(chunks));
  chunks->waitat += len;
  chunks->ack = 0;
  if(chunks->waitat > chunks->waiting)
  {
    chunks->writeat += chunks->waiting;
    chunks->waiting = chunks->waitat = 0;
    if(chunks->waiting == chunks->cap) chunks->blocked = chunks->blocking;
    if(len == 1 && chunks->writing && chunks->writeat == lob_len(chunks->writing))
    {
      struct lob_struct *old = lob_shift(chunks->writing);
      chunks->writing = old->next;
      old->next = ((void *)0);
      lob_free(old);
      chunks->writeat = 0;
      chunks->blocked = chunks->blocking;
    }
  }
  return chunks;
}


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

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

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

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

original_code:
int16_t util_chunks_size(util_chunks_t chunks)
{
  if(!util_chunks_len(chunks)) return -1;
  return chunks->waiting;
}

canonical_original_code:
short util_chunks_size(struct util_chunks_struct *chunks)
{
  if(!util_chunks_len(chunks)) return -1;
  return chunks->waiting;
}

return_type: short


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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 26) )
result = *(_QWORD *)(a1 + 16) + lob_raw(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 26) )
result = *(_QWORD *)(a1 + 16) + lob_raw(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
uint8_t *util_chunks_frame(util_chunks_t chunks)
{
  if(!chunks || !chunks->waiting) return ((void *)0);
  return lob_raw(chunks->writing)+chunks->writeat;
}

canonical_original_code:
unsigned char *util_chunks_frame(struct util_chunks_struct *chunks)
{
  if(!chunks || !chunks->waiting) return ((void *)0);
  return lob_raw(chunks->writing)+chunks->writeat;
}


decompiled_code:
__int64 __fastcall util_chunks_peek(__int64 a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax

v1 = util_chunks_size(a1);
if ( (__int16)v1 <= 0 )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = lob_len(*(_QWORD *)(a1 + 8));
LOWORD(v2) = *(_WORD *)(a1 + 16) + v2;
return (unsigned int)(v3 - v2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // eax
int v2; // ebx
int v3; // eax

v1 = func11(a1);
if ( (__int16)v1 <= 0 )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = lob_len(*(_QWORD *)(a1 + 8));
LOWORD(v2) = *(_WORD *)(a1 + 16) + v2;
return (unsigned int)(v3 - v2);
}

original_code:
int16_t util_chunks_peek(util_chunks_t chunks)
{
  int16_t size = util_chunks_size(chunks);
  if(size <= 0) return -1;
  return lob_len(chunks->writing) - (chunks->writeat+size);
}

canonical_original_code:
short util_chunks_peek(struct util_chunks_struct *chunks)
{
  short size = util_chunks_size(chunks);
  if(size <= 0) return -1;
  return lob_len(chunks->writing) - (chunks->writeat+size);
}

variable_types: size short


decompiled_code:
__int64 __fastcall util_chunks_next(__int64 a1)
{
__int16 v1; // ax
__int16 v2; // bx
__int64 result; // rax

v1 = util_chunks_size(a1);
if ( v1 >= 0 && (v2 = v1, util_chunks_written(a1, 1uLL)) && util_chunks_written(a1, v2) )
result = a1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int16 v1; // ax
__int16 v2; // bx
__int64 result; // rax

v1 = func11(a1);
if ( v1 >= 0 && (v2 = v1, func9(a1, 1uLL)) && func9(a1, v2) )
result = a1;
else
result = 0LL;
return result;
}

original_code:
util_chunks_t util_chunks_next(util_chunks_t chunks)
{
  int16_t size = util_chunks_size(chunks);
  if(size < 0) return ((void *)0);
  if(!util_chunks_written(chunks,1)) return ((void *)0);
  if(!util_chunks_written(chunks,size)) return ((void *)0);
  return chunks;
}

canonical_original_code:
struct util_chunks_struct *util_chunks_next(struct util_chunks_struct *chunks)
{
  short size = util_chunks_size(chunks);
  if(size < 0) return ((void *)0);
  if(!util_chunks_written(chunks,1)) return ((void *)0);
  if(!util_chunks_written(chunks,size)) return ((void *)0);
  return chunks;
}


decompiled_code:
__int64 __fastcall chan_new(__int64 a1)
{
unsigned int v1; // ebx
const char *v2; // r13
_DWORD *v3; // rax
_DWORD *v4; // r12
const char *v6; // r8
__int64 v7; // rdx

if ( !a1 )
return util_sys_log(7LL, "src/chan.c", 14LL, "chan_new", "open packet required");
v1 = lob_get_int(a1, "c");
if ( v1 )
{
v2 = (const char *)lob_get(a1, "type");
if ( v2 )
{
v3 = calloc(0x50uLL, 1uLL);
v3[4] = v1;
v4 = v3;
v3[18] = 1;
*((_QWORD *)v3 + 3) = lob_get(a1, "type");
util_sys_log(7LL, "src/chan.c", 26LL, "chan_new", "new channel %d %s", v1, v2);
return (__int64)v4;
}
v6 = "missing channel type";
v7 = 18LL;
}
else
{
v6 = "invalid channel id";
v7 = 16LL;
}
return util_sys_log(7LL, "src/chan.c", v7, "chan_new", v6);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
const char *v2; // r13
_DWORD *v3; // rax
_DWORD *v4; // r12
const char *v6; // r8
__int64 v7; // rdx

if ( !a1 )
return util_sys_log(7LL, "src/chan.c", 14LL, "chan_new", "open packet required");
v1 = lob_get_int(a1, "c");
if ( v1 )
{
v2 = (const char *)lob_get(a1, "type");
if ( v2 )
{
v3 = calloc(0x50uLL, 1uLL);
v3[4] = v1;
v4 = v3;
v3[18] = 1;
*((_QWORD *)v3 + 3) = lob_get(a1, "type");
util_sys_log(7LL, "src/chan.c", 26LL, "chan_new", "new channel %d %s", v1, v2);
return (__int64)v4;
}
v6 = "missing channel type";
v7 = 18LL;
}
else
{
v6 = "invalid channel id";
v7 = 16LL;
}
return util_sys_log(7LL, "src/chan.c", v7, "chan_new", v6);
}

original_code:
chan_t chan_new(lob_t open)
{
  uint32_t id;
  char *type;
  chan_t c;
  if(!open) return util_sys_log(7, "src/chan.c", 14, __func__, "open packet required");
  id = (uint32_t)lob_get_int(open,"c");
  if(!id) return util_sys_log(7, "src/chan.c", 16, __func__, "invalid channel id");
  type = lob_get(open,"type");
  if(!type) return util_sys_log(7, "src/chan.c", 18, __func__, "missing channel type");
  c = malloc(sizeof (struct chan_struct));
  memset(c,0,sizeof (struct chan_struct));
  c->state = CHAN_OPENING;
  c->id = id;
  c->type = lob_get(open,"type");
  util_sys_log(7, "src/chan.c", 26, __func__, "new channel %d %s",id,type);
  return c;
}

canonical_original_code:
struct chan_struct *chan_new(struct lob_struct *open)
{
  unsigned int id;
  char *type;
  struct chan_struct *c;
  if(!open) return util_sys_log(7, "src/chan.c", 14, __func__, "open packet required");
  id = (unsigned int)lob_get_int(open,"c");
  if(!id) return util_sys_log(7, "src/chan.c", 16, __func__, "invalid channel id");
  type = lob_get(open,"type");
  if(!type) return util_sys_log(7, "src/chan.c", 18, __func__, "missing channel type");
  c = malloc(sizeof (struct chan_struct));
  memset(c,0,sizeof (struct chan_struct));
  c->state = CHAN_OPENING;
  c->id = id;
  c->type = lob_get(open,"type");
  util_sys_log(7, "src/chan.c", 26, __func__, "new channel %d %s",id,type);
  return c;
}

variable_types:
open
struct lob_struct *

variable_types:
id
unsigned int

variable_types:
type
char *

variable_types: struct chan_struct { 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 *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; } *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; } *

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: 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 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 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 __fastcall chan_free(void *ptr)
{
if ( ptr )
{
lob_freeall(*((_QWORD *)ptr + 4));
free(ptr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
if ( ptr )
{
lob_freeall(*((_QWORD *)ptr + 4));
free(ptr);
}
return 0LL;
}

original_code:
chan_t chan_free(chan_t c)
{
  if(!c) return ((void *)0);
  if(0 && c->state != CHAN_ENDED && c->handle)
  {
    chan_err(c, "closed");
    c->handle(c, c->arg);
  }
  lob_freeall(c->in);
  free(c);
  return ((void *)0);
}

canonical_original_code:
struct chan_struct *chan_free(struct chan_struct *c)
{
  if(!c) return ((void *)0);
  if(0 && c->state != CHAN_ENDED && c->handle)
  {
    chan_err(c, "closed");
    c->handle(c, c->arg);
  }
  lob_freeall(c->in);
  free(c);
  return ((void *)0);
}

variable_types:
c
struct chan_struct *

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


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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
uint32_t chan_id(chan_t c)
{
  if(!c) return 0;
  return c->id;
}

canonical_original_code:
unsigned int chan_id(struct chan_struct *c)
{
  if(!c) return 0;
  return c->id;
}

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

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

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 e3x_self_struct { struct lob_struct *keys[2]; void *locals[2]; }


decompiled_code:
__int64 __fastcall chan_timeout(__int64 a1, unsigned int a2)
{
if ( !a1 )
return 0LL;
if ( !a2 )
return *(unsigned int *)(a1 + 48);
*(_DWORD *)(a1 + 48) = a2;
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
if ( !a1 )
return 0LL;
if ( !a2 )
return *(unsigned int *)(a1 + 48);
*(_DWORD *)(a1 + 48) = a2;
return a2;
}

original_code:
uint32_t chan_timeout(chan_t c, uint32_t at)
{
  if(!c) return 0;
  if(!at) return c->timeout;
  c->timeout = at;
  return c->timeout;
}

canonical_original_code:
unsigned int chan_timeout(struct chan_struct *c, unsigned int at)
{
  if(!c) return 0;
  if(!at) return c->timeout;
  c->timeout = at;
  return c->timeout;
}

variable_types:
at
unsigned int


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

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

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

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

original_code:
chan_t chan_next(chan_t c)
{
  if(!c) return ((void *)0);
  return c->next;
}

canonical_original_code:
struct chan_struct *chan_next(struct chan_struct *c)
{
  if(!c) return ((void *)0);
  return c->next;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 72);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 72);
else
result = 0LL;
return result;
}

original_code:
enum chan_states chan_state(chan_t c)
{
  if(!c) return CHAN_ENDED;
  return c->state;
}

canonical_original_code:
enum chan_states chan_state(struct chan_struct *c)
{
  if(!c) return CHAN_ENDED;
  return c->state;
}

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


decompiled_code:
__int64 __fastcall chan_receive(__int64 a1, __int64 a2)
{
if ( !a1 || !a2 )
return util_sys_log(7LL, "src/chan.c", 83LL, "chan_receive", "bad args");
*(_QWORD *)(a1 + 32) = lob_push(*(_QWORD *)(a1 + 32));
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
if ( !a1 || !a2 )
return util_sys_log(7LL, "src/chan.c", 83LL, "chan_receive", "bad args");
*(_QWORD *)(a1 + 32) = lob_push(*(_QWORD *)(a1 + 32));
return a1;
}

original_code:
chan_t chan_receive(chan_t c, lob_t inner)
{
  if(!c || !inner) return util_sys_log(7, "src/chan.c", 83, __func__, "bad args");
  c->in = lob_push(c->in, inner);
  return c;
}

canonical_original_code:
struct chan_struct *chan_receive(struct chan_struct *c, struct lob_struct *inner)
{
  if(!c || !inner) return util_sys_log(7, "src/chan.c", 83, __func__, "bad args");
  c->in = lob_push(c->in, inner);
  return c;
}

variable_types:
inner
struct lob_struct *


decompiled_code:
__int64 __fastcall chan_sync(__int64 a1, unsigned __int8 a2)
{
if ( a1 )
util_sys_log(7LL, "src/chan.c", 93LL, "chan_sync", "%d sync %d TODO", *(unsigned int *)(a1 + 16), a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int8 a2)
{
if ( a1 )
util_sys_log(7LL, "src/chan.c", 93LL, "chan_sync", "%d sync %d TODO", *(unsigned int *)(a1 + 16), a2);
return a1;
}

original_code:
chan_t chan_sync(chan_t c, uint8_t sync)
{
  if(!c) return ((void *)0);
  util_sys_log(7, "src/chan.c", 93, __func__, "%d sync %d TODO",c->id,sync);
  return c;
}

canonical_original_code:
struct chan_struct *chan_sync(struct chan_struct *c, unsigned char sync)
{
  if(!c) return ((void *)0);
  util_sys_log(7, "src/chan.c", 93, __func__, "%d sync %d TODO",c->id,sync);
  return c;
}

variable_types:
sync
unsigned char


original_code:
lob_t chan_receiving(chan_t c)
{
  lob_t ret;
  if(!c || !c->in) return ((void *)0);
  ret = lob_shift(c->in);
  c->in = ret->next;
  ret->next = ((void *)0);
  if(lob_get(ret,"end")) c->state = CHAN_ENDED;
  return ret;
}

canonical_original_code:
struct lob_struct *chan_receiving(struct chan_struct *c)
{
  struct lob_struct *ret;
  if(!c || !c->in) return ((void *)0);
  ret = lob_shift(c->in);
  c->in = ret->next;
  ret->next = ((void *)0);
  if(lob_get(ret,"end")) c->state = CHAN_ENDED;
  return ret;
}

variable_types: struct chan_struct { 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 *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 *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; } *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; } *

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


decompiled_code:
__int64 __fastcall chan_oob(__int64 a1)
{
__int64 v1; // r12

if ( !a1 )
return 0LL;
v1 = lob_new();
lob_set_uint(v1, "c", *(unsigned int *)(a1 + 16));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // r12

if ( !a1 )
return 0LL;
v1 = lob_new();
lob_set_uint(v1, "c", *(unsigned int *)(a1 + 16));
return v1;
}

original_code:
lob_t chan_oob(chan_t c)
{
  if(!c) return ((void *)0);
  lob_t ret = lob_new();
  lob_set_uint(ret,"c",c->id);
  return ret;
}

canonical_original_code:
struct lob_struct *chan_oob(struct chan_struct *c)
{
  if(!c) return ((void *)0);
  struct lob_struct *ret = lob_new();
  lob_set_uint(ret,"c",c->id);
  return ret;
}


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

if ( a1 )
result = chan_oob(a1);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = func9(a1);
else
result = 0LL;
return result;
}

original_code:
lob_t chan_packet(chan_t c)
{
  lob_t ret;
  if(!c) return ((void *)0);
  ret = chan_oob(c);
  return ret;
}

canonical_original_code:
struct lob_struct *chan_packet(struct chan_struct *c)
{
  struct lob_struct *ret;
  if(!c) return ((void *)0);
  ret = chan_oob(c);
  return ret;
}


decompiled_code:
__int64 __fastcall chan_send(unsigned int *a1, __int64 a2)
{
const char *v3; // rax
__int64 v4; // rsi
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // [rsp-10h] [rbp-28h]

if ( !a1 || !a2 )
return util_sys_log(7LL, "src/chan.c", 139LL, "chan_send", "bad args");
v3 = (const char *)lob_json(a2);
util_sys_log(7LL, "src/chan.c", 141LL, "chan_send", "channel send %d %s", a1[4], v3);
if ( *(_QWORD *)a1 )
{
v4 = e3x_exchange_send(*(_QWORD *)(*(_QWORD *)a1 + 8LL), a2, v7);
link_send(*(_QWORD *)a1, v4);
lob_free(a2, v4, v5);
result = (__int64)a1;
}
else
{
lob_free(a2, "src/chan.c", v7);
result = util_sys_log(7LL, "src/chan.c", 145LL, "chan_send", "dropping packet, no link");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, __int64 a2)
{
const char *v3; // rax
__int64 v4; // rsi
__int64 v5; // rdx
__int64 result; // rax
__int64 v7; // [rsp-10h] [rbp-28h]

if ( !a1 || !a2 )
return util_sys_log(7LL, "src/chan.c", 139LL, "chan_send", "bad args");
v3 = (const char *)lob_json(a2);
util_sys_log(7LL, "src/chan.c", 141LL, "chan_send", "channel send %d %s", a1[4], v3);
if ( *(_QWORD *)a1 )
{
v4 = e3x_exchange_send(*(_QWORD *)(*(_QWORD *)a1 + 8LL), a2, v7);
link_send(*(_QWORD *)a1, v4);
lob_free(a2, v4, v5);
result = (__int64)a1;
}
else
{
lob_free(a2, "src/chan.c", v7);
result = util_sys_log(7LL, "src/chan.c", 145LL, "chan_send", "dropping packet, no link");
}
return result;
}

original_code:
chan_t chan_send(chan_t c, lob_t inner)
{
  if(!c || !inner) return util_sys_log(7, "src/chan.c", 139, __func__, "bad args");
  util_sys_log(7, "src/chan.c", 141, __func__, "channel send %d %s",c->id,lob_json(inner));
  if(!c->link)
  {
    lob_free(inner);
    return util_sys_log(7, "src/chan.c", 145, __func__, "dropping packet, no link");
  }
  link_send(c->link, e3x_exchange_send(c->link->x, inner));
  lob_free(inner);
  return c;
}

canonical_original_code:
struct chan_struct *chan_send(struct chan_struct *c, struct lob_struct *inner)
{
  if(!c || !inner) return util_sys_log(7, "src/chan.c", 139, __func__, "bad args");
  util_sys_log(7, "src/chan.c", 141, __func__, "channel send %d %s",c->id,lob_json(inner));
  if(!c->link)
  {
    lob_free(inner);
    return util_sys_log(7, "src/chan.c", 145, __func__, "dropping packet, no link");
  }
  link_send(c->link, e3x_exchange_send(c->link->x, inner));
  lob_free(inner);
  return c;
}


decompiled_code:
__int64 __fastcall chan_err(__int64 a1, const char *a2)
{
const char *v2; // r13
__int64 v3; // rbp

if ( a1 )
{
v2 = a2;
if ( !a2 )
v2 = "unknown";
v3 = lob_new();
lob_set_uint(v3, "c", *(unsigned int *)(a1 + 16));
lob_set_raw(v3, "end", 3LL, "true", 4LL);
lob_set(v3, "err", v2);
*(_QWORD *)(a1 + 32) = lob_push(*(_QWORD *)(a1 + 32));
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2)
{
const char *v2; // r13
__int64 v3; // rbp

if ( a1 )
{
v2 = a2;
if ( !a2 )
v2 = "unknown";
v3 = lob_new();
lob_set_uint(v3, "c", *(unsigned int *)(a1 + 16));
lob_set_raw(v3, "end", 3LL, "true", 4LL);
lob_set(v3, "err", v2);
*(_QWORD *)(a1 + 32) = lob_push(*(_QWORD *)(a1 + 32));
}
return a1;
}

original_code:
chan_t chan_err(chan_t c, char *msg)
{
  if(!c) return ((void *)0);
  if(!msg) msg = "unknown";
  lob_t err = lob_new();
  lob_set_uint(err,"c",c->id);
  lob_set_raw(err, "end", 3, "true", 4);
  lob_set(err, "err", msg);
  c->in = lob_push(c->in, err);
  return c;
}

canonical_original_code:
struct chan_struct *chan_err(struct chan_struct *c, char *msg)
{
  if(!c) return ((void *)0);
  if(!msg) msg = "unknown";
  struct lob_struct *err = lob_new();
  lob_set_uint(err,"c",c->id);
  lob_set_raw(err, "end", 3, "true", 4);
  lob_set(err, "err", msg);
  c->in = lob_push(c->in, err);
  return c;
}

variable_types:
msg
char *


decompiled_code:
void *__fastcall chan_process(void *ptr, unsigned int a2)
{
unsigned int v2; // eax
int v3; // edx
void (__fastcall *v4)(void *, _QWORD); // rax

if ( !ptr )
return ptr;
if ( a2 )
{
v2 = *((_DWORD *)ptr + 12);
if ( v2 )
{
if ( v2 < a2 )
{
*((_DWORD *)ptr + 12) = 0;
chan_err((__int64)ptr, "timeout");
}
else
{
v3 = *((_DWORD *)ptr + 11);
if ( v3 )
*((_DWORD *)ptr + 12) = a2 + v2 - v3;
}
}
*((_DWORD *)ptr + 11) = a2;
}
if ( *((_QWORD *)ptr + 4) )
{
v4 = (void (__fastcall *)(void *, _QWORD))*((_QWORD *)ptr + 8);
if ( v4 )
v4(ptr, *((_QWORD *)ptr + 7));
}
if ( *((_DWORD *)ptr + 18) )
return ptr;
util_sys_log(7LL, "src/chan.c", 196LL, "chan_process", "channel is now ended, freeing it");
return (void *)chan_free(ptr);
}

canonical_decompiled_code:
void *__fastcall func13(void *ptr, unsigned int a2)
{
unsigned int v2; // eax
int v3; // edx
void (__fastcall *v4)(void *, _QWORD); // rax

if ( !ptr )
return ptr;
if ( a2 )
{
v2 = *((_DWORD *)ptr + 12);
if ( v2 )
{
if ( v2 < a2 )
{
*((_DWORD *)ptr + 12) = 0;
func12((__int64)ptr, "timeout");
}
else
{
v3 = *((_DWORD *)ptr + 11);
if ( v3 )
*((_DWORD *)ptr + 12) = a2 + v2 - v3;
}
}
*((_DWORD *)ptr + 11) = a2;
}
if ( *((_QWORD *)ptr + 4) )
{
v4 = (void (__fastcall *)(void *, _QWORD))*((_QWORD *)ptr + 8);
if ( v4 )
v4(ptr, *((_QWORD *)ptr + 7));
}
if ( *((_DWORD *)ptr + 18) )
return ptr;
util_sys_log(7LL, "src/chan.c", 196LL, "chan_process", "channel is now ended, freeing it");
return (void *)func1(ptr);
}

original_code:
chan_t chan_process(chan_t c, uint32_t now)
{
  if(!c) return ((void *)0);
  if(now)
  {
    if(c->timeout)
    {
      if(now > c->timeout)
      {
        c->timeout = 0;
        chan_err(c, "timeout");
      }else if(c->trecv){
        c->timeout += (now - c->trecv);
      }
    }
    c->trecv = now;
  }
  if(c->in && c->handle) c->handle(c, c->arg);
  if(c->state == CHAN_ENDED)
  {
    util_sys_log(7, "src/chan.c", 196, __func__, "channel is now ended, freeing it");
    c = chan_free(c);
  }
  return c;
}

canonical_original_code:
struct chan_struct *chan_process(struct chan_struct *c, unsigned int now)
{
  if(!c) return ((void *)0);
  if(now)
  {
    if(c->timeout)
    {
      if(now > c->timeout)
      {
        c->timeout = 0;
        chan_err(c, "timeout");
      }else if(c->trecv){
        c->timeout += (now - c->trecv);
      }
    }
    c->trecv = now;
  }
  if(c->in && c->handle) c->handle(c, c->arg);
  if(c->state == CHAN_ENDED)
  {
    util_sys_log(7, "src/chan.c", 196, __func__, "channel is now ended, freeing it");
    c = chan_free(c);
  }
  return c;
}

variable_types:
now
unsigned int


decompiled_code:
__int64 __fastcall chan_size(__int64 a1)
{
__int64 v1; // rbx
unsigned int i; // er12
int v3; // eax

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(a1 + 32);
for ( i = 0; v1; i += v3 )
{
v3 = lob_len(v1);
v1 = *(_QWORD *)(v1 + 72);
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 v1; // rbx
unsigned int i; // er12
int v3; // eax

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(a1 + 32);
for ( i = 0; v1; i += v3 )
{
v3 = lob_len(v1);
v1 = *(_QWORD *)(v1 + 72);
}
return i;
}

original_code:
uint32_t chan_size(chan_t c)
{
  uint32_t size = 0;
  lob_t cur;
  if(!c) return 0;
  cur = c->in;
  while(cur)
  {
    size += lob_len(cur);
    cur = cur->next;
  }
  return size;
}

canonical_original_code:
unsigned int chan_size(struct chan_struct *c)
{
  unsigned int size = 0;
  struct lob_struct *cur;
  if(!c) return 0;
  cur = c->in;
  while(cur)
  {
    size += lob_len(cur);
    cur = cur->next;
  }
  return size;
}

variable_types:
size
unsigned int


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

result = a1;
if ( !a1 )
return util_sys_log(7LL, "src/chan.c", 224LL, "chan_handle", "bad args");
*(_QWORD *)(a1 + 64) = a2;
*(_QWORD *)(a1 + 56) = a3;
return result;
}

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

result = a1;
if ( !a1 )
return util_sys_log(7LL, "src/chan.c", 224LL, "chan_handle", "bad args");
*(_QWORD *)(a1 + 64) = a2;
*(_QWORD *)(a1 + 56) = a3;
return result;
}

original_code:
chan_t chan_handle(chan_t c, void (*handle)(chan_t c, void *arg), void *arg)
{
  if(!c) return util_sys_log(7, "src/chan.c", 224, __func__, "bad args");
  c->handle = handle;
  c->arg = arg;
  return c;
}

canonical_original_code:
struct chan_struct *chan_handle(struct chan_struct *c, void (*handle)(struct chan_struct *c, void *arg), void *arg)
{
  if(!c) return util_sys_log(7, "src/chan.c", 224, __func__, "bad args");
  c->handle = handle;
  c->arg = arg;
  return c;
}

variable_types: void (*)(struct chan_struct *c, void *arg)

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall jwt_decode(char *s, size_t n)
{
size_t v2; // rdx
char *v3; // rbx
char *v4; // rax
const char *v5; // r8
__int64 v6; // rdx
char *v7; // rbp
_BYTE *v8; // rax
char *v9; // r13
signed __int64 v10; // rbx
__int64 v11; // r14
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
const char *v18; // r8
__int64 v19; // rdx
__int64 v21; // [rsp+0h] [rbp-48h]
__int64 v22; // [rsp+8h] [rbp-40h]

if ( !s )
return 0LL;
v2 = n;
if ( !n )
v2 = strlen(s);
v3 = &s[v2];
v4 = (char *)memchr(s, 46, v2);
v5 = "missing/bad first separator";
v6 = 27LL;
if ( v4 )
{
v7 = v4 + 1;
v8 = memchr(v4 + 1, 46, v3 - (v4 + 1));
if ( v8 )
{
v9 = v8 + 1;
v10 = v3 - (v8 + 1);
if ( base64_decoder(v8 + 1, v10, 0LL) )
{
if ( base64_decoder(v7, v9 - v7 - 1, 0LL) )
{
if ( base64_decoder(s, v7 - s - 1, 0LL) )
{
v22 = v7 - s - 1;
v21 = lob_new();
v11 = lob_link(0LL, v21);
v12 = base64_decoder(v7, v9 - v7 - 1, 0LL);
lob_head(v21, 0LL, v12);
v13 = lob_head_get(v21);
base64_decoder(v7, v9 - v7 - 1, v13);
v14 = base64_decoder(v9, v10, 0LL);
lob_body(v21, 0LL, v14);
v15 = lob_body_get(v21);
base64_decoder(v9, v10, v15);
v16 = base64_decoder(s, v22, 0LL);
lob_head(v11, 0LL, v16);
v17 = lob_head_get(v11);
base64_decoder(s, v22, v17);
return v11;
}
v18 = "invalid header b64: %.*s";
v19 = 36LL;
}
else
{
v18 = "invalid claims base64: %.*s";
v19 = 35LL;
}
}
else
{
v18 = "invalid sig base64: %.*s";
v19 = 34LL;
}
return util_sys_log(6LL, "src/lib/jwt.c", v19, "jwt_decode", v18);
}
v5 = "missing/bad second separator";
v6 = 30LL;
}
return util_sys_log(6LL, "src/lib/jwt.c", v6, "jwt_decode", v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, size_t n)
{
size_t v2; // rdx
char *v3; // rbx
char *v4; // rax
const char *v5; // r8
__int64 v6; // rdx
char *v7; // rbp
_BYTE *v8; // rax
char *v9; // r13
signed __int64 v10; // rbx
__int64 v11; // r14
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
const char *v18; // r8
__int64 v19; // rdx
__int64 v21; // [rsp+0h] [rbp-48h]
__int64 v22; // [rsp+8h] [rbp-40h]

if ( !s )
return 0LL;
v2 = n;
if ( !n )
v2 = strlen(s);
v3 = &s[v2];
v4 = (char *)memchr(s, 46, v2);
v5 = "missing/bad first separator";
v6 = 27LL;
if ( v4 )
{
v7 = v4 + 1;
v8 = memchr(v4 + 1, 46, v3 - (v4 + 1));
if ( v8 )
{
v9 = v8 + 1;
v10 = v3 - (v8 + 1);
if ( base64_decoder(v8 + 1, v10, 0LL) )
{
if ( base64_decoder(v7, v9 - v7 - 1, 0LL) )
{
if ( base64_decoder(s, v7 - s - 1, 0LL) )
{
v22 = v7 - s - 1;
v21 = lob_new();
v11 = lob_link(0LL, v21);
v12 = base64_decoder(v7, v9 - v7 - 1, 0LL);
lob_head(v21, 0LL, v12);
v13 = lob_head_get(v21);
base64_decoder(v7, v9 - v7 - 1, v13);
v14 = base64_decoder(v9, v10, 0LL);
lob_body(v21, 0LL, v14);
v15 = lob_body_get(v21);
base64_decoder(v9, v10, v15);
v16 = base64_decoder(s, v22, 0LL);
lob_head(v11, 0LL, v16);
v17 = lob_head_get(v11);
base64_decoder(s, v22, v17);
return v11;
}
v18 = "invalid header b64: %.*s";
v19 = 36LL;
}
else
{
v18 = "invalid claims base64: %.*s";
v19 = 35LL;
}
}
else
{
v18 = "invalid sig base64: %.*s";
v19 = 34LL;
}
return util_sys_log(6LL, "src/lib/jwt.c", v19, "jwt_decode", v18);
}
v5 = "missing/bad second separator";
v6 = 30LL;
}
return util_sys_log(6LL, "src/lib/jwt.c", v6, "jwt_decode", v5);
}

original_code:
lob_t jwt_decode(char *encoded, size_t len)
{
  lob_t header, claims;
  char *dot1, *dot2, *end;
  if(!encoded) return ((void *)0);
  if(!len) len = strlen(encoded);
  end = encoded+len;
  dot1 = memchr(encoded,'.',(end-encoded));
  if(!dot1) return util_sys_log(6, "src/lib/jwt.c", 27, __func__, "missing/bad first separator");
  dot1++;
  dot2 = memchr(dot1,'.',(end-dot1));
  if(!dot2) return util_sys_log(6, "src/lib/jwt.c", 30, __func__, "missing/bad second separator");
  dot2++;
  if(!base64_decoder(dot2, (end-dot2), ((void *)0))) return util_sys_log(6, "src/lib/jwt.c", 34, __func__, "invalid sig base64: %.*s",(end-dot2),dot2);
  if(!base64_decoder(dot1, (dot2-dot1)-1, ((void *)0))) return util_sys_log(6, "src/lib/jwt.c", 35, __func__, "invalid claims base64: %.*s",(dot2-dot1)-1,dot1);
  if(!base64_decoder(encoded, (dot1-encoded)-1, ((void *)0))) return util_sys_log(6, "src/lib/jwt.c", 36, __func__, "invalid header b64: %.*s",(dot1-encoded)-1,encoded);
  claims = lob_new();
  header = lob_link(((void *)0), claims);
  lob_head(claims, ((void *)0), base64_decoder(dot1, (dot2-dot1)-1, ((void *)0)));
  base64_decoder(dot1, (dot2-dot1)-1, lob_head_get(claims));
  lob_body(claims, ((void *)0), base64_decoder(dot2, (end-dot2), ((void *)0)));
  base64_decoder(dot2, (end-dot2), lob_body_get(claims));
  lob_head(header, ((void *)0), base64_decoder(encoded, (dot1-encoded)-1, ((void *)0)));
  base64_decoder(encoded, (dot1-encoded)-1, lob_head_get(header));
  return header;
}

canonical_original_code:
struct lob_struct *jwt_decode(char *encoded, unsigned long len)
{
  struct lob_struct *header; struct lob_struct *claims;
  char *dot1; char *dot2; char *end;
  if(!encoded) return ((void *)0);
  if(!len) len = strlen(encoded);
  end = encoded+len;
  dot1 = memchr(encoded,'.',(end-encoded));
  if(!dot1) return util_sys_log(6, "src/lib/jwt.c", 27, __func__, "missing/bad first separator");
  dot1++;
  dot2 = memchr(dot1,'.',(end-dot1));
  if(!dot2) return util_sys_log(6, "src/lib/jwt.c", 30, __func__, "missing/bad second separator");
  dot2++;
  if(!base64_decoder(dot2, (end-dot2), ((void *)0))) return util_sys_log(6, "src/lib/jwt.c", 34, __func__, "invalid sig base64: %.*s",(end-dot2),dot2);
  if(!base64_decoder(dot1, (dot2-dot1)-1, ((void *)0))) return util_sys_log(6, "src/lib/jwt.c", 35, __func__, "invalid claims base64: %.*s",(dot2-dot1)-1,dot1);
  if(!base64_decoder(encoded, (dot1-encoded)-1, ((void *)0))) return util_sys_log(6, "src/lib/jwt.c", 36, __func__, "invalid header b64: %.*s",(dot1-encoded)-1,encoded);
  claims = lob_new();
  header = lob_link(((void *)0), claims);
  lob_head(claims, ((void *)0), base64_decoder(dot1, (dot2-dot1)-1, ((void *)0)));
  base64_decoder(dot1, (dot2-dot1)-1, lob_head_get(claims));
  lob_body(claims, ((void *)0), base64_decoder(dot2, (end-dot2), ((void *)0)));
  base64_decoder(dot2, (end-dot2), lob_body_get(claims));
  lob_head(header, ((void *)0), base64_decoder(encoded, (dot1-encoded)-1, ((void *)0)));
  base64_decoder(encoded, (dot1-encoded)-1, lob_head_get(header));
  return header;
}

variable_types:
encoded
char *

variable_types:
len
unsigned long

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

variable_types:
end
char *


decompiled_code:
__int64 jwt_parse()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
lob_t jwt_parse(uint8_t *raw, size_t len)
{
  return ((void *)0);
}

canonical_original_code:
struct lob_struct *jwt_parse(unsigned char *raw, unsigned long len)
{
  return ((void *)0);
}

variable_types:
raw
unsigned char *


decompiled_code:
// attributes: thunk
__int64 jwt_claims()
{
return lob_linked();
}

canonical_decompiled_code:
__int64 func2()
{
return lob_linked();
}

original_code:
lob_t jwt_claims(lob_t token)
{
  return lob_linked(token);
}

canonical_original_code:
struct lob_struct *jwt_claims(struct lob_struct *token)
{
  return lob_linked(token);
}

variable_types:
token
struct lob_struct *


original_code:
char *jwt_encode(lob_t token)
{
  lob_t claims = jwt_claims(token);
  if(!claims) return util_sys_log(4, "src/lib/jwt.c", 72, __func__, "no claims");
  size_t slen = (8 * (((claims->body_len) + 2) / 6)) + 3;
  size_t clen = (8 * (((claims->head_len) + 2) / 6)) + 3;
  size_t hlen = (8 * (((token->head_len) + 2) / 6)) + 3;
  char *encoded;
  if(!(encoded = malloc(hlen+1+clen+1+slen+1))) return util_sys_log(4, "src/lib/jwt.c", 78, __func__, "OOM");
  hlen = base64_encoder(token->head,token->head_len,encoded);
  encoded[hlen] = '.';
  clen = base64_encoder(claims->head,claims->head_len,encoded+hlen+1);
  encoded[hlen+1+clen] = '.';
  slen = base64_encoder(claims->body,claims->body_len,encoded+hlen+1+clen+1);
  encoded[hlen+1+clen+1+slen] = 0;
  return encoded;
}

canonical_original_code:
char *jwt_encode(struct lob_struct *token)
{
  struct lob_struct *claims = jwt_claims(token);
  if(!claims) return util_sys_log(4, "src/lib/jwt.c", 72, __func__, "no claims");
  unsigned long slen = (8 * (((claims->body_len) + 2) / 6)) + 3;
  unsigned long clen = (8 * (((claims->head_len) + 2) / 6)) + 3;
  unsigned long hlen = (8 * (((token->head_len) + 2) / 6)) + 3;
  char *encoded;
  if(!(encoded = malloc(hlen+1+clen+1+slen+1))) return util_sys_log(4, "src/lib/jwt.c", 78, __func__, "OOM");
  hlen = base64_encoder(token->head,token->head_len,encoded);
  encoded[hlen] = '.';
  clen = base64_encoder(claims->head,claims->head_len,encoded+hlen+1);
  encoded[hlen+1+clen] = '.';
  slen = base64_encoder(claims->body,claims->body_len,encoded+hlen+1+clen+1);
  encoded[hlen+1+clen+1+slen] = 0;
  return encoded;
}

variable_types:
slen
unsigned long

variable_types:
clen
unsigned long

variable_types:
hlen
unsigned long

return_type: char *


decompiled_code:
__int64 jwt_raw()
{
return util_sys_log(6LL, "src/lib/jwt.c", 94LL, "jwt_raw", "TODO");
}

canonical_decompiled_code:
__int64 func4()
{
return util_sys_log(6LL, "src/lib/jwt.c", 94LL, "jwt_raw", "TODO");
}

original_code:
uint8_t *jwt_raw(lob_t token)
{
  return util_sys_log(6, "src/lib/jwt.c", 94, __func__, "TODO");
}

canonical_original_code:
unsigned char *jwt_raw(struct lob_struct *token)
{
  return util_sys_log(6, "src/lib/jwt.c", 94, __func__, "TODO");
}


decompiled_code:
__int64 jwt_len()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 0LL;
}

original_code:
uint32_t jwt_len(lob_t token)
{
  return 0;
}

canonical_original_code:
unsigned int jwt_len(struct lob_struct *token)
{
  return 0;
}


decompiled_code:
__int64 __fastcall jwt_verify(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r13
const char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // rbx
__int64 v8; // rax
unsigned __int8 v9; // bl
__int64 result; // rax

v2 = jwt_claims();
if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 107LL, "jwt_verify", "bad args");
v3 = v2;
if ( !v2 )
return util_sys_log(7LL, "src/lib/jwt.c", 107LL, "jwt_verify", "bad args");
v4 = (const char *)jwt_encode(a1);
v5 = (char *)v4;
if ( !v4 )
return util_sys_log(7LL, "src/lib/jwt.c", 111LL, "jwt_verify", "bad token");
v6 = strchr(v4, 46);
v7 = (char *)(strchr(v6 + 1, 46) - v5);
v8 = lob_body_len(v3);
util_sys_log(7LL, "src/lib/jwt.c", 115LL, "jwt_verify", "checking %lu %.*s", v8, (int)v7, v5);
v9 = e3x_exchange_validate(a2, a1, v3, v5, v7);
free(v5);
if ( v9 )
result = util_sys_log(7LL, "src/lib/jwt.c", 121LL, "jwt_verify", "validate failed: %d", v9);
else
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r13
const char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // rbx
__int64 v8; // rax
unsigned __int8 v9; // bl
__int64 result; // rax

v2 = func2();
if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 107LL, "jwt_verify", "bad args");
v3 = v2;
if ( !v2 )
return util_sys_log(7LL, "src/lib/jwt.c", 107LL, "jwt_verify", "bad args");
v4 = (const char *)func3(a1);
v5 = (char *)v4;
if ( !v4 )
return util_sys_log(7LL, "src/lib/jwt.c", 111LL, "jwt_verify", "bad token");
v6 = strchr(v4, 46);
v7 = (char *)(strchr(v6 + 1, 46) - v5);
v8 = lob_body_len(v3);
util_sys_log(7LL, "src/lib/jwt.c", 115LL, "jwt_verify", "checking %lu %.*s", v8, (int)v7, v5);
v9 = e3x_exchange_validate(a2, a1, v3, v5, v7);
free(v5);
if ( v9 )
result = util_sys_log(7LL, "src/lib/jwt.c", 121LL, "jwt_verify", "validate failed: %d", v9);
else
result = a1;
return result;
}

original_code:
lob_t jwt_verify(lob_t token, e3x_exchange_t x)
{
  lob_t claims = jwt_claims(token);
  if(!token || !claims) return util_sys_log(7, "src/lib/jwt.c", 107, __func__, "bad args");
  char *encoded = jwt_encode(token);
  if(!encoded) return util_sys_log(7, "src/lib/jwt.c", 111, __func__, "bad token");
  char *dot = strchr(encoded,'.');
  dot = strchr(dot+1,'.');
  util_sys_log(7, "src/lib/jwt.c", 115, __func__, "checking %lu %.*s",lob_body_len(claims),dot-encoded,encoded);
  uint8_t err = e3x_exchange_validate(x, token, claims, (uint8_t*)encoded, dot-encoded);
  free(encoded);
  if(err) return util_sys_log(7, "src/lib/jwt.c", 121, __func__, "validate failed: %d",err);
  return token;
}

canonical_original_code:
struct lob_struct *jwt_verify(struct lob_struct *token, struct e3x_exchange_struct *x)
{
  struct lob_struct *claims = jwt_claims(token);
  if(!token || !claims) return util_sys_log(7, "src/lib/jwt.c", 107, __func__, "bad args");
  char *encoded = jwt_encode(token);
  if(!encoded) return util_sys_log(7, "src/lib/jwt.c", 111, __func__, "bad token");
  char *dot = strchr(encoded,'.');
  dot = strchr(dot+1,'.');
  util_sys_log(7, "src/lib/jwt.c", 115, __func__, "checking %lu %.*s",lob_body_len(claims),dot-encoded,encoded);
  unsigned char err = e3x_exchange_validate(x, token, claims, (uint8_t*)encoded, dot-encoded);
  free(encoded);
  if(err) return util_sys_log(7, "src/lib/jwt.c", 121, __func__, "validate failed: %d",err);
  return token;
}

variable_types: 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 { 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]; } *

variable_types:
dot
char *

variable_types:
err
unsigned char


decompiled_code:
__int64 __fastcall jwt_sign(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r13
const char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // rax

v2 = jwt_claims();
if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 129LL, "jwt_sign", "bad args");
v3 = v2;
if ( !v2 )
return util_sys_log(7LL, "src/lib/jwt.c", 129LL, "jwt_sign", "bad args");
v4 = (const char *)jwt_encode(a1);
v5 = (char *)v4;
if ( !v4 )
return util_sys_log(7LL, "src/lib/jwt.c", 133LL, "jwt_sign", "bad token");
v6 = strchr(v4, 46);
v7 = strchr(v6 + 1, 46);
if ( !e3x_self_sign(a2, a1, v5, v7 - v5) )
return util_sys_log(7LL, "src/lib/jwt.c", 138LL, "jwt_sign", "signing failed");
free(v5);
lob_body(v3, *(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16));
lob_body(a1, 0LL, 0LL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // r13
const char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // rax

v2 = func2();
if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 129LL, "jwt_sign", "bad args");
v3 = v2;
if ( !v2 )
return util_sys_log(7LL, "src/lib/jwt.c", 129LL, "jwt_sign", "bad args");
v4 = (const char *)func3(a1);
v5 = (char *)v4;
if ( !v4 )
return util_sys_log(7LL, "src/lib/jwt.c", 133LL, "jwt_sign", "bad token");
v6 = strchr(v4, 46);
v7 = strchr(v6 + 1, 46);
if ( !e3x_self_sign(a2, a1, v5, v7 - v5) )
return util_sys_log(7LL, "src/lib/jwt.c", 138LL, "jwt_sign", "signing failed");
free(v5);
lob_body(v3, *(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16));
lob_body(a1, 0LL, 0LL);
return a1;
}

original_code:
lob_t jwt_sign(lob_t token, e3x_self_t self)
{
  lob_t claims = jwt_claims(token);
  if(!token || !claims) return util_sys_log(7, "src/lib/jwt.c", 129, __func__, "bad args");
  char *encoded = jwt_encode(token);
  if(!encoded) return util_sys_log(7, "src/lib/jwt.c", 133, __func__, "bad token");
  char *dot = strchr(encoded,'.');
  dot = strchr(dot+1,'.');
  if(!e3x_self_sign(self, token, (uint8_t*)encoded, dot-encoded)) return util_sys_log(7, "src/lib/jwt.c", 138, __func__, "signing failed");
  free(encoded);
  lob_body(claims,token->body,token->body_len);
  lob_body(token,((void *)0),0);
  return token;
}

canonical_original_code:
struct lob_struct *jwt_sign(struct lob_struct *token, struct e3x_self_struct *self)
{
  struct lob_struct *claims = jwt_claims(token);
  if(!token || !claims) return util_sys_log(7, "src/lib/jwt.c", 129, __func__, "bad args");
  char *encoded = jwt_encode(token);
  if(!encoded) return util_sys_log(7, "src/lib/jwt.c", 133, __func__, "bad token");
  char *dot = strchr(encoded,'.');
  dot = strchr(dot+1,'.');
  if(!e3x_self_sign(self, token, (unsigned char *)encoded, dot-encoded)) return util_sys_log(7, "src/lib/jwt.c", 138, __func__, "signing failed");
  free(encoded);
  lob_body(claims,token->body,token->body_len);
  lob_body(token,((void *)0),0);
  return token;
}

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


decompiled_code:
__int64 __fastcall jwk_local_get(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // r14
__int64 (__fastcall *v8)(__int64, __int64, _QWORD, __int64); // r15
const char *v9; // rdi
__int64 result; // rax

if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 158LL, "jwk_local_get", "missing/bad args");
v4 = a3;
v5 = 0LL;
while ( 1 )
{
v6 = *(_QWORD *)((char *)&e3x_cipher_sets + v5);
if ( v6 )
{
v7 = *(_QWORD *)(a1 + v5 + 16);
if ( v7 )
{
v8 = *(__int64 (__fastcall **)(__int64, __int64, _QWORD, __int64))(v6 + 56);
if ( v8 )
{
v9 = *(const char **)(v6 + 144);
if ( v9 )
{
if ( strstr(v9, "JWK") )
{
result = v8(v7, a2, 0LL, v4);
if ( result )
break;
}
}
}
}
}
v5 += 8LL;
if ( v5 == 16 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // r14
__int64 (__fastcall *v8)(__int64, __int64, _QWORD, __int64); // r15
const char *v9; // rdi
__int64 result; // rax

if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 158LL, "jwk_local_get", "missing/bad args");
v4 = a3;
v5 = 0LL;
while ( 1 )
{
v6 = *(_QWORD *)((char *)&e3x_cipher_sets + v5);
if ( v6 )
{
v7 = *(_QWORD *)(a1 + v5 + 16);
if ( v7 )
{
v8 = *(__int64 (__fastcall **)(__int64, __int64, _QWORD, __int64))(v6 + 56);
if ( v8 )
{
v9 = *(const char **)(v6 + 144);
if ( v9 )
{
if ( strstr(v9, "JWK") )
{
result = v8(v7, a2, 0LL, v4);
if ( result )
break;
}
}
}
}
}
v5 += 8LL;
if ( v5 == 16 )
return 0LL;
}
return result;
}

original_code:
lob_t jwk_local_get(e3x_self_t self, lob_t jwk, _Bool private)
{
  if(!self) return util_sys_log(7, "src/lib/jwt.c", 158, __func__, "missing/bad args");
  for(uint8_t i=0; i<2; i++)
  {
    e3x_cipher_t cs = e3x_cipher_sets[i];
    if(!cs || !self->locals[i] || !cs->local_sign || !cs->alg || !strstr(cs->alg,"JWK")) continue;
    lob_t ret = cs->local_sign(self->locals[i],jwk,((void *)0),private?1:0);
    if(ret) return ret;
  }
  return ((void *)0);
}

canonical_original_code:
struct lob_struct *jwk_local_get(struct e3x_self_struct *self, struct lob_struct *jwk, _Bool private)
{
  if(!self) return util_sys_log(7, "src/lib/jwt.c", 158, __func__, "missing/bad args");
  for(unsigned char i = 0; i<2; i++)
  {
    struct e3x_cipher_struct *cs = e3x_cipher_sets[i];
    if(!cs || !self->locals[i] || !cs->local_sign || !cs->alg || !strstr(cs->alg,"JWK")) continue;
    struct lob_struct *ret = cs->local_sign(self->locals[i],jwk,((void *)0),private?1:0);
    if(ret) return ret;
  }
  return ((void *)0);
}

variable_types:
jwk
struct lob_struct *

variable_types:
i
unsigned char

variable_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 { 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]; } *


decompiled_code:
__int64 __fastcall jwk_local_load(__int64 a1, char a2)
{
__int64 v2; // r13
__int64 v3; // r12

if ( !a1 || !lob_get(a1, "kty") )
return util_sys_log(7LL, "src/lib/jwt.c", 172LL, "jwk_local_load", "missing/bad args");
v2 = 0LL;
if ( a2 )
v2 = lob_new();
v3 = e3x_self_new(v2, a1);
lob_free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char a2)
{
__int64 v2; // r13
__int64 v3; // r12

if ( !a1 || !lob_get(a1, "kty") )
return util_sys_log(7LL, "src/lib/jwt.c", 172LL, "jwk_local_load", "missing/bad args");
v2 = 0LL;
if ( a2 )
v2 = lob_new();
v3 = e3x_self_new(v2, a1);
lob_free(v2);
return v3;
}

original_code:
e3x_self_t jwk_local_load(lob_t jwk, _Bool generate)
{
  if(!jwk || !lob_get(jwk,"kty")) return util_sys_log(7, "src/lib/jwt.c", 172, __func__, "missing/bad args");
  lob_t gen = ((void *)0);
  if(generate) gen = lob_new();
  e3x_self_t self = e3x_self_new(gen, jwk);
  lob_free(gen);
  return self;
}

canonical_original_code:
struct e3x_self_struct *jwk_local_load(struct lob_struct *jwk, _Bool generate)
{
  if(!jwk || !lob_get(jwk,"kty")) return util_sys_log(7, "src/lib/jwt.c", 172, __func__, "missing/bad args");
  struct lob_struct *gen = ((void *)0);
  if(generate) gen = lob_new();
  struct e3x_self_struct *self = e3x_self_new(gen, jwk);
  lob_free(gen);
  return self;
}

variable_types: struct e3x_self_struct { 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[2]; void *locals[2]; } *


decompiled_code:
__int64 jwk_remote_get()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0LL;
}

original_code:
lob_t jwk_remote_get(e3x_exchange_t x, lob_t jwk)
{
  return ((void *)0);
}

canonical_original_code:
struct lob_struct *jwk_remote_get(struct e3x_exchange_struct *x, struct lob_struct *jwk)
{
  return ((void *)0);
}


decompiled_code:
__int64 __fastcall jwk_remote_load(__int64 a1)
{
char *v2; // rbx
__int64 v3; // r12
__int64 (__fastcall *v4)(__int64, _QWORD); // r13
const char *v5; // rdi
void *v6; // rdi
const char *v8; // rax

if ( !a1 || !lob_get(a1, "kty") )
return util_sys_log(7LL, "src/lib/jwt.c", 187LL, "jwk_remote_load", "missing/bad args");
v2 = (char *)&e3x_cipher_sets;
do
{
v3 = *(_QWORD *)v2;
if ( *(_QWORD *)v2 )
{
v4 = *(__int64 (__fastcall **)(__int64, _QWORD))(v3 + 64);
if ( v4 )
{
v5 = *(const char **)(v3 + 144);
if ( v5 )
{
if ( strstr(v5, "JWK") )
{
v6 = (void *)v4(a1, 0LL);
if ( v6 )
{
free(v6);
return e3x_exchange_new(0LL, *(unsigned __int8 *)(v3 + 137), a1);
}
}
}
}
}
v2 += 8;
}
while ( v2 != (char *)&e3x_cipher_sets + 16 );
v8 = (const char *)lob_json(a1);
return util_sys_log(4LL, "src/lib/jwt.c", 200LL, "jwk_remote_load", "unsupported JWK: %s", v8);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
char *v2; // rbx
__int64 v3; // r12
__int64 (__fastcall *v4)(__int64, _QWORD); // r13
const char *v5; // rdi
void *v6; // rdi
const char *v8; // rax

if ( !a1 || !lob_get(a1, "kty") )
return util_sys_log(7LL, "src/lib/jwt.c", 187LL, "jwk_remote_load", "missing/bad args");
v2 = (char *)&e3x_cipher_sets;
do
{
v3 = *(_QWORD *)v2;
if ( *(_QWORD *)v2 )
{
v4 = *(__int64 (__fastcall **)(__int64, _QWORD))(v3 + 64);
if ( v4 )
{
v5 = *(const char **)(v3 + 144);
if ( v5 )
{
if ( strstr(v5, "JWK") )
{
v6 = (void *)v4(a1, 0LL);
if ( v6 )
{
free(v6);
return e3x_exchange_new(0LL, *(unsigned __int8 *)(v3 + 137), a1);
}
}
}
}
}
v2 += 8;
}
while ( v2 != (char *)&e3x_cipher_sets + 16 );
v8 = (const char *)lob_json(a1);
return util_sys_log(4LL, "src/lib/jwt.c", 200LL, "jwk_remote_load", "unsupported JWK: %s", v8);
}

original_code:
e3x_exchange_t jwk_remote_load(lob_t jwk)
{
  if(!jwk || !lob_get(jwk,"kty")) return util_sys_log(7, "src/lib/jwt.c", 187, __func__, "missing/bad args");
  for(uint8_t i=0; i<2; i++)
  {
    e3x_cipher_t cs = e3x_cipher_sets[i];
    void* remote = ((void *)0);
    if(!cs || !cs->remote_new || !cs->alg || !strstr(cs->alg,"JWK")) continue;
    if(!(remote = cs->remote_new(jwk,((void *)0)))) continue;
    free(remote);
    return e3x_exchange_new(((void *)0), cs->csid, jwk);
  }
  return util_sys_log(4, "src/lib/jwt.c", 200, __func__, "unsupported JWK: %s",lob_json(jwk));
}

canonical_original_code:
struct e3x_exchange_struct *jwk_remote_load(struct lob_struct *jwk)
{
  if(!jwk || !lob_get(jwk,"kty")) return util_sys_log(7, "src/lib/jwt.c", 187, __func__, "missing/bad args");
  for(unsigned char i = 0; i<2; i++)
  {
    struct e3x_cipher_struct *cs = e3x_cipher_sets[i];
    void *remote = ((void *)0);
    if(!cs || !cs->remote_new || !cs->alg || !strstr(cs->alg,"JWK")) continue;
    if(!(remote = cs->remote_new(jwk,((void *)0)))) continue;
    free(remote);
    return e3x_exchange_new(((void *)0), cs->csid, jwk);
  }
  return util_sys_log(4, "src/lib/jwt.c", 200, __func__, "unsupported JWK: %s",lob_json(jwk));
}

variable_types:
remote
void *

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


decompiled_code:
__int64 __fastcall jwe_encrypt_1c(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r13
__int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // r12
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // r12
__int64 v11; // rax
__int64 v12; // rax
const char *v13; // rbx
size_t v14; // rax
__int64 v15; // r13
__int64 v16; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v21; // [rsp+8h] [rbp-50h]
char v22[72]; // [rsp+10h] [rbp-48h] BYREF

v3 = a3;
v4 = lob_new();
lob_set(v4, "kty", "EC");
lob_set(v4, "crv", "P-256");
v5 = jwk_local_load(v4, 1);
lob_free(v4);
v6 = lob_new();
lob_set(v6, "kty", "EC");
lob_set(v6, "crv", "P-256");
jwk_local_get(v5, v6, 0);
v7 = lob_new();
lob_set(v7, "alg", "ECDH-EH+A128CTR-HS256");
lob_set(v7, "enc", "A128CTR-HS256");
e3x_rand(v22, 8LL);
lob_set_base64(v7, "hks", v22, 8LL);
e3x_rand(v22, 16LL);
lob_set_base64(v7, "iv", v22, 16LL);
v8 = lob_json(v6);
lob_set_raw(v7, "epk", 3LL, v8, 0LL);
lob_free(v6);
lob_body(v7, v3, 32LL);
v9 = lob_new();
lob_set(v9, "req", "ECDH HK256 A128CTR HS256");
lob_link(v7, v9);
if ( !(*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64))(*a1 + 88LL))(
a1[2],
*(_QWORD *)(v5 + 8LL * *(unsigned __int8 *)(*a1 + 136LL) + 16),
v7) )
{
v18 = lob_json(v7);
util_sys_log(4LL, "src/lib/jwt.c", 262LL, "jwe_encrypt_1c", "JWE failed for %s", v18);
return lob_free(v7);
}
lob_unlink(v7);
v10 = lob_new();
v21 = lob_body_len(v7);
v11 = lob_body_get(v7);
lob_set_base64(v10, "encrypted_key", v11, v21);
v12 = lob_json(v7);
lob_set_raw(v10, "header", 6LL, v12, 0LL);
v13 = (const char *)jwt_encode(a2);
v14 = strlen(v13);
lob_body(v10, v13, v14);
e3x_rand(v22, 16LL);
lob_set_base64(v10, "iv", v22, 16LL);
lob_set(v9, "req", "A128CTR HS256");
lob_body(v9, a3, 32LL);
lob_link(v10, v9);
if ( !(*(__int64 (__fastcall **)(_QWORD, __int64, __int64))(*a1 + 88LL))(a1[2], v5, v10) )
{
v19 = lob_json(v7);
util_sys_log(4LL, "src/lib/jwt.c", 282LL, "jwe_encrypt_1c", "JWE failed for %s", v19);
return lob_free(v7);
}
lob_unlink(v10);
lob_free(v9);
lob_link(v10, v7);
v15 = lob_body_len(v10);
v16 = lob_body_get(v10);
lob_set_base64(v10, "ciphertext", v16, v15);
lob_body(v10, 0LL, 0LL);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r13
__int64 v4; // rbp
__int64 v5; // r14
__int64 v6; // r12
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // r12
__int64 v11; // rax
__int64 v12; // rax
const char *v13; // rbx
size_t v14; // rax
__int64 v15; // r13
__int64 v16; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v21; // [rsp+8h] [rbp-50h]
char v22[72]; // [rsp+10h] [rbp-48h] BYREF

v3 = a3;
v4 = lob_new();
lob_set(v4, "kty", "EC");
lob_set(v4, "crv", "P-256");
v5 = func10(v4, 1);
lob_free(v4);
v6 = lob_new();
lob_set(v6, "kty", "EC");
lob_set(v6, "crv", "P-256");
func9(v5, v6, 0);
v7 = lob_new();
lob_set(v7, "alg", "ECDH-EH+A128CTR-HS256");
lob_set(v7, "enc", "A128CTR-HS256");
e3x_rand(v22, 8LL);
lob_set_base64(v7, "hks", v22, 8LL);
e3x_rand(v22, 16LL);
lob_set_base64(v7, "iv", v22, 16LL);
v8 = lob_json(v6);
lob_set_raw(v7, "epk", 3LL, v8, 0LL);
lob_free(v6);
lob_body(v7, v3, 32LL);
v9 = lob_new();
lob_set(v9, "req", "ECDH HK256 A128CTR HS256");
lob_link(v7, v9);
if ( !(*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64))(*a1 + 88LL))(
a1[2],
*(_QWORD *)(v5 + 8LL * *(unsigned __int8 *)(*a1 + 136LL) + 16),
v7) )
{
v18 = lob_json(v7);
util_sys_log(4LL, "src/lib/jwt.c", 262LL, "jwe_encrypt_1c", "JWE failed for %s", v18);
return lob_free(v7);
}
lob_unlink(v7);
v10 = lob_new();
v21 = lob_body_len(v7);
v11 = lob_body_get(v7);
lob_set_base64(v10, "encrypted_key", v11, v21);
v12 = lob_json(v7);
lob_set_raw(v10, "header", 6LL, v12, 0LL);
v13 = (const char *)func3(a2);
v14 = strlen(v13);
lob_body(v10, v13, v14);
e3x_rand(v22, 16LL);
lob_set_base64(v10, "iv", v22, 16LL);
lob_set(v9, "req", "A128CTR HS256");
lob_body(v9, a3, 32LL);
lob_link(v10, v9);
if ( !(*(__int64 (__fastcall **)(_QWORD, __int64, __int64))(*a1 + 88LL))(a1[2], v5, v10) )
{
v19 = lob_json(v7);
util_sys_log(4LL, "src/lib/jwt.c", 282LL, "jwe_encrypt_1c", "JWE failed for %s", v19);
return lob_free(v7);
}
lob_unlink(v10);
lob_free(v9);
lob_link(v10, v7);
v15 = lob_body_len(v10);
v16 = lob_body_get(v10);
lob_set_base64(v10, "ciphertext", v16, v15);
lob_body(v10, 0LL, 0LL);
return v10;
}

original_code:
lob_t jwe_encrypt_1c(e3x_exchange_t to, lob_t jwt, uint8_t *ckey)
{
  uint8_t buf[16];
  lob_t ek = lob_new();
  lob_set(ek,"kty","EC"); lob_set(ek,"crv","P-256");
  e3x_self_t ephem = jwk_local_load(ek, 1);
  ek = lob_free(ek);
  lob_t epk = lob_new();
  lob_set(epk,"kty","EC");
  lob_set(epk,"crv","P-256");
  jwk_local_get(ephem, epk, 0);
  lob_t header = lob_new();
  lob_set(header,"alg","ECDH-EH+A128CTR-HS256");
  lob_set(header,"enc","A128CTR-HS256");
  e3x_rand(buf,8);
  lob_set_base64(header,"hks",buf,8);
  e3x_rand(buf,16);
  lob_set_base64(header,"iv",buf,16);
  lob_set_raw(header,"epk",3,lob_json(epk),0);
  epk = lob_free(epk);
  lob_body(header,ckey,32);
  lob_t key = lob_new();
  lob_set(key,"req","ECDH HK256 A128CTR HS256");
  lob_link(header,key);
  if(!to->cs->remote_encrypt(to->remote,ephem->locals[to->cs->id],header))
  {
    util_sys_log(4, "src/lib/jwt.c", 262, __func__, "JWE failed for %s",lob_json(header));
    return lob_free(header);
  }
  lob_unlink(header);
  lob_t jwe = lob_new();
  lob_set_base64(jwe,"encrypted_key",lob_body_get(header),lob_body_len(header));
  lob_set_raw(jwe,"header",6,lob_json(header),0);
  char *encoded = jwt_encode(jwt);
  lob_body(jwe,(uint8_t*)encoded,strlen(encoded));
  e3x_rand(buf,16);
  lob_set_base64(jwe,"iv",buf,16);
  lob_set(key,"req","A128CTR HS256");
  lob_body(key,ckey,32);
  lob_link(jwe,key);
  if(!to->cs->remote_encrypt(to->remote,ephem,jwe))
  {
    util_sys_log(4, "src/lib/jwt.c", 282, __func__, "JWE failed for %s",lob_json(header));
    return lob_free(header);
  }
  lob_unlink(jwe);
  lob_free(key);
  lob_link(jwe,header);
  lob_set_base64(jwe,"ciphertext",lob_body_get(jwe),lob_body_len(jwe));
  lob_body(jwe,((void *)0),0);
  return jwe;
}

canonical_original_code:
struct lob_struct *jwe_encrypt_1c(struct e3x_exchange_struct *to, struct lob_struct *jwt, unsigned char *ckey)
{
  unsigned char buf[16];
  struct lob_struct *ek = lob_new();
  lob_set(ek,"kty","EC"); lob_set(ek,"crv","P-256");
  struct e3x_self_struct *ephem = jwk_local_load(ek, 1);
  ek = lob_free(ek);
  struct lob_struct *epk = lob_new();
  lob_set(epk,"kty","EC");
  lob_set(epk,"crv","P-256");
  jwk_local_get(ephem, epk, 0);
  struct lob_struct *header = lob_new();
  lob_set(header,"alg","ECDH-EH+A128CTR-HS256");
  lob_set(header,"enc","A128CTR-HS256");
  e3x_rand(buf,8);
  lob_set_base64(header,"hks",buf,8);
  e3x_rand(buf,16);
  lob_set_base64(header,"iv",buf,16);
  lob_set_raw(header,"epk",3,lob_json(epk),0);
  epk = lob_free(epk);
  lob_body(header,ckey,32);
  struct lob_struct *key = lob_new();
  lob_set(key,"req","ECDH HK256 A128CTR HS256");
  lob_link(header,key);
  if(!to->cs->remote_encrypt(to->remote,ephem->locals[to->cs->id],header))
  {
    util_sys_log(4, "src/lib/jwt.c", 262, __func__, "JWE failed for %s",lob_json(header));
    return lob_free(header);
  }
  lob_unlink(header);
  struct lob_struct *jwe = lob_new();
  lob_set_base64(jwe,"encrypted_key",lob_body_get(header),lob_body_len(header));
  lob_set_raw(jwe,"header",6,lob_json(header),0);
  char *encoded = jwt_encode(jwt);
  lob_body(jwe,(unsigned char *)encoded,strlen(encoded));
  e3x_rand(buf,16);
  lob_set_base64(jwe,"iv",buf,16);
  lob_set(key,"req","A128CTR HS256");
  lob_body(key,ckey,32);
  lob_link(jwe,key);
  if(!to->cs->remote_encrypt(to->remote,ephem,jwe))
  {
    util_sys_log(4, "src/lib/jwt.c", 282, __func__, "JWE failed for %s",lob_json(header));
    return lob_free(header);
  }
  lob_unlink(jwe);
  lob_free(key);
  lob_link(jwe,header);
  lob_set_base64(jwe,"ciphertext",lob_body_get(jwe),lob_body_len(jwe));
  lob_body(jwe,((void *)0),0);
  return jwe;
}

variable_types:
jwt
struct lob_struct *

variable_types:
ckey
unsigned char *

variable_types:
buf
unsigned char [16]

variable_types:
encoded
char *


decompiled_code:
__int64 __fastcall jwe_decrypt_1c(__int64 a1, __int64 a2, __m128i *a3)
{
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // r13
__int64 v8; // r15
__int64 v9; // rsi
__int64 v10; // r15
const __m128i *v11; // rax
__int64 v12; // r13
__int64 v13; // rax
size_t v14; // r12
char *v15; // rax
__int64 result; // rax
const char *v17; // rax
const char *v18; // rax
__int64 v19; // [rsp+8h] [rbp-40h]
__int64 v20; // [rsp+8h] [rbp-40h]

v5 = e3x_cipher_set(28LL, 0LL);
if ( !v5 )
return util_sys_log(7LL, "src/lib/jwt.c", 298LL, "jwe_decrypt_1c", "cs1c unavailable");
if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 298LL, "jwe_decrypt_1c", "cs1c unavailable");
v6 = v5;
if ( !*(_QWORD *)(a1 + 8LL * *(unsigned __int8 *)(v5 + 136) + 16) )
return util_sys_log(7LL, "src/lib/jwt.c", 298LL, "jwe_decrypt_1c", "cs1c unavailable");
v7 = lob_get_json(a2, "header");
v8 = lob_get_base64(a2, "encrypted_key");
v19 = lob_body_len(v8);
v9 = lob_body_get(v8);
lob_body(v7, v9, v19);
v10 = lob_new();
lob_set(v10, "req", "ECDH HK256 A128CTR HS256");
lob_link(v7, v10);
if ( (*(__int64 (__fastcall **)(_QWORD, __int64))(v6 + 48))(
*(_QWORD *)(a1 + 8LL * *(unsigned __int8 *)(v6 + 136) + 16),
v7) )
{
lob_unlink(v7);
v11 = (const __m128i *)lob_body_get(v7);
*a3 = _mm_loadu_si128(v11);
a3[1] = _mm_loadu_si128(v11 + 1);
v12 = lob_get_base64(a2, "ciphertext");
v20 = lob_body_len(v12);
v13 = lob_body_get(v12);
lob_body(a2, v13, v20);
lob_set(v10, "req", "A128CTR HS256");
lob_body(v10, a3, 32LL);
lob_link(a2, v10);
if ( (*(__int64 (__fastcall **)(_QWORD, __int64))(v6 + 48))(
*(_QWORD *)(a1 + 8LL * *(unsigned __int8 *)(v6 + 136) + 16),
a2) )
{
lob_unlink(a2);
v14 = lob_body_len(a2);
v15 = (char *)lob_body_get(a2);
result = jwt_decode(v15, v14);
}
else
{
v18 = (const char *)lob_json(a2);
util_sys_log(4LL, "src/lib/jwt.c", 325LL, "jwe_decrypt_1c", "JWE failed for %s", v18);
result = 0LL;
}
}
else
{
v17 = (const char *)lob_json(v7);
util_sys_log(4LL, "src/lib/jwt.c", 311LL, "jwe_decrypt_1c", "JWE failed for %s", v17);
result = lob_free(v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __m128i *a3)
{
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // r13
__int64 v8; // r15
__int64 v9; // rsi
__int64 v10; // r15
const __m128i *v11; // rax
__int64 v12; // r13
__int64 v13; // rax
size_t v14; // r12
char *v15; // rax
__int64 result; // rax
const char *v17; // rax
const char *v18; // rax
__int64 v19; // [rsp+8h] [rbp-40h]
__int64 v20; // [rsp+8h] [rbp-40h]

v5 = e3x_cipher_set(28LL, 0LL);
if ( !v5 )
return util_sys_log(7LL, "src/lib/jwt.c", 298LL, "jwe_decrypt_1c", "cs1c unavailable");
if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 298LL, "jwe_decrypt_1c", "cs1c unavailable");
v6 = v5;
if ( !*(_QWORD *)(a1 + 8LL * *(unsigned __int8 *)(v5 + 136) + 16) )
return util_sys_log(7LL, "src/lib/jwt.c", 298LL, "jwe_decrypt_1c", "cs1c unavailable");
v7 = lob_get_json(a2, "header");
v8 = lob_get_base64(a2, "encrypted_key");
v19 = lob_body_len(v8);
v9 = lob_body_get(v8);
lob_body(v7, v9, v19);
v10 = lob_new();
lob_set(v10, "req", "ECDH HK256 A128CTR HS256");
lob_link(v7, v10);
if ( (*(__int64 (__fastcall **)(_QWORD, __int64))(v6 + 48))(
*(_QWORD *)(a1 + 8LL * *(unsigned __int8 *)(v6 + 136) + 16),
v7) )
{
lob_unlink(v7);
v11 = (const __m128i *)lob_body_get(v7);
*a3 = _mm_loadu_si128(v11);
a3[1] = _mm_loadu_si128(v11 + 1);
v12 = lob_get_base64(a2, "ciphertext");
v20 = lob_body_len(v12);
v13 = lob_body_get(v12);
lob_body(a2, v13, v20);
lob_set(v10, "req", "A128CTR HS256");
lob_body(v10, a3, 32LL);
lob_link(a2, v10);
if ( (*(__int64 (__fastcall **)(_QWORD, __int64))(v6 + 48))(
*(_QWORD *)(a1 + 8LL * *(unsigned __int8 *)(v6 + 136) + 16),
a2) )
{
lob_unlink(a2);
v14 = lob_body_len(a2);
v15 = (char *)lob_body_get(a2);
result = func0(v15, v14);
}
else
{
v18 = (const char *)lob_json(a2);
util_sys_log(4LL, "src/lib/jwt.c", 325LL, "jwe_decrypt_1c", "JWE failed for %s", v18);
result = 0LL;
}
}
else
{
v17 = (const char *)lob_json(v7);
util_sys_log(4LL, "src/lib/jwt.c", 311LL, "jwe_decrypt_1c", "JWE failed for %s", v17);
result = lob_free(v7);
}
return result;
}

original_code:
lob_t jwe_decrypt_1c(e3x_self_t self, lob_t jwe, uint8_t *ckey)
{
  e3x_cipher_t cs = e3x_cipher_set(0x1c,((void *)0));
  if(!cs || !self || !self->locals[cs->id]) return util_sys_log(7, "src/lib/jwt.c", 298, __func__, "cs1c unavailable");
  lob_t header = lob_get_json(jwe,"header");
  lob_t ekey = lob_get_base64(jwe,"encrypted_key");
  lob_body(header,lob_body_get(ekey),lob_body_len(ekey));
  lob_t key = lob_new();
  lob_set(key,"req","ECDH HK256 A128CTR HS256");
  lob_link(header,key);
  if(!cs->local_decrypt(self->locals[cs->id],header))
  {
    util_sys_log(4, "src/lib/jwt.c", 311, __func__, "JWE failed for %s",lob_json(header));
    return lob_free(header);
  }
  lob_unlink(header);
  memcpy(ckey,lob_body_get(header),32);
  lob_t ctext = lob_get_base64(jwe,"ciphertext");
  lob_body(jwe,lob_body_get(ctext),lob_body_len(ctext));
  lob_set(key,"req","A128CTR HS256");
  lob_body(key,ckey,32);
  lob_link(jwe,key);
  if(!cs->local_decrypt(self->locals[cs->id],jwe))
  {
    util_sys_log(4, "src/lib/jwt.c", 325, __func__, "JWE failed for %s",lob_json(jwe));
    return ((void *)0);
  }
  lob_unlink(jwe);
  return jwt_decode((char*)lob_body_get(jwe),lob_body_len(jwe));
}

canonical_original_code:
struct lob_struct *jwe_decrypt_1c(struct e3x_self_struct *self, struct lob_struct *jwe, unsigned char *ckey)
{
  struct e3x_cipher_struct *cs = e3x_cipher_set(0x1c,((void *)0));
  if(!cs || !self || !self->locals[cs->id]) return util_sys_log(7, "src/lib/jwt.c", 298, __func__, "cs1c unavailable");
  struct lob_struct *header = lob_get_json(jwe,"header");
  struct lob_struct *ekey = lob_get_base64(jwe,"encrypted_key");
  lob_body(header,lob_body_get(ekey),lob_body_len(ekey));
  struct lob_struct *key = lob_new();
  lob_set(key,"req","ECDH HK256 A128CTR HS256");
  lob_link(header,key);
  if(!cs->local_decrypt(self->locals[cs->id],header))
  {
    util_sys_log(4, "src/lib/jwt.c", 311, __func__, "JWE failed for %s",lob_json(header));
    return lob_free(header);
  }
  lob_unlink(header);
  memcpy(ckey,lob_body_get(header),32);
  struct lob_struct *ctext = lob_get_base64(jwe,"ciphertext");
  lob_body(jwe,lob_body_get(ctext),lob_body_len(ctext));
  lob_set(key,"req","A128CTR HS256");
  lob_body(key,ckey,32);
  lob_link(jwe,key);
  if(!cs->local_decrypt(self->locals[cs->id],jwe))
  {
    util_sys_log(4, "src/lib/jwt.c", 325, __func__, "JWE failed for %s",lob_json(jwe));
    return ((void *)0);
  }
  lob_unlink(jwe);
  return jwt_decode((char *)lob_body_get(jwe),lob_body_len(jwe));
}

variable_types:
jwe
struct lob_struct *

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


decompiled_code:
__int64 __fastcall jwt_alg(__int64 a1)
{
__int64 v1; // r12

if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 151LL, "jwt_alg", "missing arg");
v1 = a1;
if ( !e3x_cipher_set(0LL, a1) )
v1 = 0LL;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // r12

if ( !a1 )
return util_sys_log(7LL, "src/lib/jwt.c", 151LL, "jwt_alg", "missing arg");
v1 = a1;
if ( !e3x_cipher_set(0LL, a1) )
v1 = 0LL;
return v1;
}

original_code:
char *jwt_alg(char *alg)
{
  if(!alg) return util_sys_log(7, "src/lib/jwt.c", 151, __func__, "missing arg");
  return (e3x_cipher_set(0,alg)) ? alg : ((void *)0);
}

variable_types:
alg
char *


decompiled_code:
void __fastcall e3x_self_free(void *ptr)
{
__int64 v1; // rax

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) && e3x_cipher_sets[0] )
{
(*(void (**)(void))(e3x_cipher_sets[0] + 40LL))();
lob_free(*(_QWORD *)ptr);
}
if ( *((_QWORD *)ptr + 3) )
{
v1 = e3x_cipher_sets[1];
if ( v1 )
{
(*(void (**)(void))(v1 + 40))();
lob_free(*((_QWORD *)ptr + 1));
}
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v1; // rax

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) && e3x_cipher_sets[0] )
{
(*(void (**)(void))(e3x_cipher_sets[0] + 40LL))();
lob_free(*(_QWORD *)ptr);
}
if ( *((_QWORD *)ptr + 3) )
{
v1 = e3x_cipher_sets[1];
if ( v1 )
{
(*(void (**)(void))(v1 + 40))();
lob_free(*((_QWORD *)ptr + 1));
}
}
free(ptr);
}
}

original_code:
void e3x_self_free(e3x_self_t self)
{
  uint8_t i;
  if(!self) return;
  for(i=0; i<2; i++)
  {
    if(!self->locals[i] || !e3x_cipher_sets[i]) continue;
    e3x_cipher_sets[i]->local_free(self->locals[i]);
    lob_free(self->keys[i]);
  }
  free(self);
  return;
}

canonical_original_code:
void e3x_self_free(struct e3x_self_struct *self)
{
  unsigned char i;
  if(!self) return;
  for(i=0; i<2; i++)
  {
    if(!self->locals[i] || !e3x_cipher_sets[i]) continue;
    e3x_cipher_sets[i]->local_free(self->locals[i]);
    lob_free(self->keys[i]);
  }
  free(self);
  return;
}

return_type: void