decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_mem_alloc(__int64 a1, int a2)
{
__int64 v4; // r14
void *v5; // rbp
__int64 result; // rax
__int64 v7; // rdx
FILE *v8; // rdi
FILE *v9; // rdi
FILE *v10; // rsi
__int64 v11; // rdx
FILE *v12; // rdi
FILE *v13; // rdi
FILE *v14; // rsi
__int64 v15; // rdx
FILE *v16; // rdi
FILE *v17; // rdi
FILE *v18; // rsi
FILE *v19; // rdi
FILE *v20; // rsi
__int64 v21; // rdx
FILE *v22; // rdi
__int64 v23; // rdx
FILE *v24; // rdi
FILE *v25; // rcx
FILE *v26; // rsi

v4 = *(_QWORD *)(a1 + 328) + 240208LL;
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v7 = (unsigned int)getpid();
v8 = (*(&kogmo_rtdb_debug + 1) & 1) != 0 ? stdout : stderr;
fprintf(v8, "%d DBG: ", v7);
v9 = (*(&kogmo_rtdb_debug + 1) & 1) != 0 ? stdout : stderr;
fprintf(v9, "mem_alloc: heap pointers: base %p", (const void *)(*(_QWORD *)(a1 + 328) + 240208LL));
v10 = (*(&kogmo_rtdb_debug + 1) & 1) != 0 ? stdout : stderr;
fputc(10, v10);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v11 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v12 = stdout;
else
v12 = stderr;
fprintf(v12, "%d DBG: ", v11);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v13 = stdout;
else
v13 = stderr;
fprintf(
v13,
"mem_alloc: %lli bytes (%lli used, %lli free)",
a2,
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL),
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v14 = stdout;
else
v14 = stderr;
fputc(10, v14);
}
}
if ( a2 <= 0 )
return 0xFFFFFFFFLL;
kogmo_rtdb_heap_lock(a1);
v5 = (void *)suba_alloc(*(_QWORD *)(a1 + 344), a2, 0LL);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v15 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "%d DBG: ", v15);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v17 = stdout;
else
v17 = stderr;
fprintf(v17, "mem_malloc: at %p", v5);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v18 = stdout;
else
v18 = stderr;
fputc(10, v18);
}
if ( v5 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL) -= a2;
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL) += a2;
kogmo_rtdb_heap_unlock(a1);
memset(v5, 0, a2);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v23 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v24 = stdout;
else
v24 = stderr;
fprintf(v24, "%d DBG: ", v23);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v25 = stdout;
else
v25 = stderr;
fwrite("allocated mem cleared", 1uLL, 0x15uLL, v25);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v26 = stdout;
else
v26 = stderr;
fputc(10, v26);
}
result = (unsigned int)((_DWORD)v5 - v4);
}
else
{
kogmo_rtdb_heap_unlock(a1);
if ( kogmo_rtdb_debug )
{
v21 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v22 = stdout;
else
v22 = stderr;
fprintf(v22, "%d ERR: in %s line %i: ", v21, "kogmo_rtdb_rtmalloc.c", 82LL);
}
else
{
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
}
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v19 = stdout;
else
v19 = stderr;
fprintf(
v19,
"object mem_alloc failed for %i continuous bytes, %lli (discontinuous) bytes free",
(unsigned int)a2,
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v20 = stdout;
else
v20 = stderr;
fputc(10, v20);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v4; // r14
void *v5; // rbp
__int64 result; // rax
__int64 v7; // rdx
FILE *v8; // rdi
FILE *v9; // rdi
FILE *v10; // rsi
__int64 v11; // rdx
FILE *v12; // rdi
FILE *v13; // rdi
FILE *v14; // rsi
__int64 v15; // rdx
FILE *v16; // rdi
FILE *v17; // rdi
FILE *v18; // rsi
FILE *v19; // rdi
FILE *v20; // rsi
__int64 v21; // rdx
FILE *v22; // rdi
__int64 v23; // rdx
FILE *v24; // rdi
FILE *v25; // rcx
FILE *v26; // rsi

v4 = *(_QWORD *)(a1 + 328) + 240208LL;
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v7 = (unsigned int)getpid();
v8 = (*(&kogmo_rtdb_debug + 1) & 1) != 0 ? stdout : stderr;
fprintf(v8, "%d DBG: ", v7);
v9 = (*(&kogmo_rtdb_debug + 1) & 1) != 0 ? stdout : stderr;
fprintf(v9, "mem_alloc: heap pointers: base %p", (const void *)(*(_QWORD *)(a1 + 328) + 240208LL));
v10 = (*(&kogmo_rtdb_debug + 1) & 1) != 0 ? stdout : stderr;
fputc(10, v10);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v11 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v12 = stdout;
else
v12 = stderr;
fprintf(v12, "%d DBG: ", v11);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v13 = stdout;
else
v13 = stderr;
fprintf(
v13,
"mem_alloc: %lli bytes (%lli used, %lli free)",
a2,
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL),
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v14 = stdout;
else
v14 = stderr;
fputc(10, v14);
}
}
if ( a2 <= 0 )
return 0xFFFFFFFFLL;
func0(a1);
v5 = (void *)suba_alloc(*(_QWORD *)(a1 + 344), a2, 0LL);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v15 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v16 = stdout;
else
v16 = stderr;
fprintf(v16, "%d DBG: ", v15);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v17 = stdout;
else
v17 = stderr;
fprintf(v17, "mem_malloc: at %p", v5);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v18 = stdout;
else
v18 = stderr;
fputc(10, v18);
}
if ( v5 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL) -= a2;
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL) += a2;
func1(a1);
memset(v5, 0, a2);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
{
v23 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v24 = stdout;
else
v24 = stderr;
fprintf(v24, "%d DBG: ", v23);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v25 = stdout;
else
v25 = stderr;
fwrite("allocated mem cleared", 1uLL, 0x15uLL, v25);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v26 = stdout;
else
v26 = stderr;
fputc(10, v26);
}
result = (unsigned int)((_DWORD)v5 - v4);
}
else
{
func1(a1);
if ( kogmo_rtdb_debug )
{
v21 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v22 = stdout;
else
v22 = stderr;
fprintf(v22, "%d ERR: in %s line %i: ", v21, "kogmo_rtdb_rtmalloc.c", 82LL);
}
else
{
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
}
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v19 = stdout;
else
v19 = stderr;
fprintf(
v19,
"object mem_alloc failed for %i continuous bytes, %lli (discontinuous) bytes free",
(unsigned int)a2,
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v20 = stdout;
else
v20 = stderr;
fputc(10, v20);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
kogmo_rtdb_objsize_t
kogmo_rtdb_obj_mem_alloc (kogmo_rtdb_handle_t *db_h, kogmo_rtdb_objsize_t size )
{
  void *ptr = ((void *)0);
  void *base = db_h->localdata_p->heap;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_alloc: heap pointers: base %p", db_h->localdata_p->heap); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_alloc: %lli bytes (%lli used, %lli free)", (long long int) size, (long long int) db_h->localdata_p->heap_used, (long long int) db_h->localdata_p->heap_free); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( size <= 0 ) return -1;
  kogmo_rtdb_heap_lock(db_h);
  ptr = suba_alloc(db_h->heapinfo, size, 0 );
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_malloc: at %p",ptr); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( ptr == ((void *)0) )
    {
      kogmo_rtdb_heap_unlock(db_h);
      do { if((kogmo_rtdb_debug)) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d ERR: in %s line %i: ",getpid(),"kogmo_rtdb_rtmalloc.c",82); } else { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"ERROR: "); } fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"object mem_alloc failed for %i continuous bytes, %lli (discontinuous) bytes free", size, (long long int) db_h->localdata_p->heap_free); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } while (0);
      return -1;
    }
  db_h->localdata_p->heap_free -= size;
  db_h->localdata_p->heap_used += size;
  kogmo_rtdb_heap_unlock(db_h);
  memset (ptr, 0, size);
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"allocated mem cleared"); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  return ptr-base;
}

canonical_original_code:
int kogmo_rtdb_obj_mem_alloc(struct kogmo_rtdb_handle_t *db_h, int size)
{
  void *ptr = ((void *)0);
  void *base = db_h->localdata_p->heap;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_alloc: heap pointers: base %p", db_h->localdata_p->heap); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_alloc: %lli bytes (%lli used, %lli free)", (long long) size, (long long) db_h->localdata_p->heap_used, (long long) db_h->localdata_p->heap_free); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( size <= 0 ) return -1;
  kogmo_rtdb_heap_lock(db_h);
  ptr = suba_alloc(db_h->heapinfo, size, 0 );
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_malloc: at %p",ptr); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if ( ptr == ((void *)0) )
    {
      kogmo_rtdb_heap_unlock(db_h);
      do { if((kogmo_rtdb_debug)) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d ERR: in %s line %i: ",getpid(),"kogmo_rtdb_rtmalloc.c",82); } else { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"ERROR: "); } fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"object mem_alloc failed for %i continuous bytes, %lli (discontinuous) bytes free", size, (long long) db_h->localdata_p->heap_free); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } while (0);
      return -1;
    }
  db_h->localdata_p->heap_free -= size;
  db_h->localdata_p->heap_used += size;
  kogmo_rtdb_heap_unlock(db_h);
  memset (ptr, 0, size);
  do { if((kogmo_rtdb_debug) & 256) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"allocated mem cleared"); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  return ptr-base;
}

variable_types: struct kogmo_rtdb_handle_t { struct kogmo_rtdb_obj_info_t { int oid; char name[32]; long created_ts; int created_proc; long lastmodified_ts; int lastmodified_proc; long deleted_ts; int deleted_proc; int parent_oid; int otype; int size_max; float history_interval; float avg_cycletime; float max_cycletime; struct { unsigned int read_deny; unsigned int write_allow; unsigned int keep_alloc; unsigned int unique; unsigned int cycle_watch; unsigned int persistent; unsigned int parent_delete; unsigned int no_notifies; unsigned int immediately_delete; unsigned int withhold_stale; } flags; int history_size; int history_slot; int buffer_idx; } procobjmeta; struct kogmo_rtdb_obj_c3_process_t { struct kogmo_rtdb_subobj_base_t { long committed_ts; int committed_proc; long data_ts; int size; } base; struct kogmo_rtdb_subobj_c3_process_t { int proc_oid; unsigned int pid; unsigned int tid; unsigned int flags; unsigned int status; char statusmsg[160]; unsigned int version; unsigned int uid; } process; } procobj; struct kogmo_rtdb_obj_local_t { unsigned long objmeta_oid_next; struct kogmo_rtdb_obj_info_t objmeta[1000]; unsigned int objmeta_free; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } objmeta_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } objmeta_changenotify; union pthread_mutex_t obj_lock[1000]; union pthread_cond_t obj_changenotify[1000]; union pthread_mutex_t obj_changenotify_lock[1000]; int rtdb_trace; int rtdb_tracebufsize; struct { unsigned int simmode; unsigned int no_notifies; } flags; long sim_ts; float default_history_interval; float default_max_cycletime; float default_keep_deleted_interval; unsigned long heap_size; unsigned long heap_free; unsigned long heap_used; union pthread_mutex_t heap_lock; char heap[1]; } *localdata_p; long localdata_size; void *heapinfo; struct kogmo_rtdb_ipc_handle_t { int shmfd; char shmid[32]; struct kogmo_rtdb_ipc_shm_t { unsigned int revision; int manager_pid; long manager_alive_ts; union pthread_mutex_t global_lock; struct kogmo_rtdb_ipc_process_t { int proc_oid; long connected_ts; long disconnected_ts; float cycletime; int pid; unsigned long tid; unsigned int flags; char name[32]; } proc[100]; unsigned int proc_free; union pthread_mutex_t proc_lock; unsigned long proc_oid_next; long data_size; } *shm_p; long shm_size; struct kogmo_rtdb_ipc_process_t this_process; int this_process_slot; int tracefd; int rxtracefd; } ipc_h; } *

variable_types: size int

variable_types:
ptr
void *

variable_types:
base
void *


repo: matgoebl/kogmo-rtdb

decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_mem_free(__int64 a1, int a2, unsigned int a3)
{
const void *v5; // r12
__int64 v7; // rdx
FILE *v8; // rdi
FILE *v9; // rdi
FILE *v10; // rsi

v5 = (const void *)(*(_QWORD *)(a1 + 328) + a2 + 240208LL);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v7 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "%d DBG: ", v7);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v9 = stdout;
else
v9 = stderr;
fprintf(v9, "mem_free: %i bytes at %p", a3, v5);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v10 = stdout;
else
v10 = stderr;
fputc(10, v10);
}
kogmo_rtdb_heap_lock(a1);
suba_free(*(_QWORD *)(a1 + 344), v5);
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL) += (int)a3;
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL) -= (int)a3;
return kogmo_rtdb_heap_unlock(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, unsigned int a3)
{
const void *v5; // r12
__int64 v7; // rdx
FILE *v8; // rdi
FILE *v9; // rdi
FILE *v10; // rsi

v5 = (const void *)(*(_QWORD *)(a1 + 328) + a2 + 240208LL);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v7 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "%d DBG: ", v7);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v9 = stdout;
else
v9 = stderr;
fprintf(v9, "mem_free: %i bytes at %p", a3, v5);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v10 = stdout;
else
v10 = stderr;
fputc(10, v10);
}
func0(a1);
suba_free(*(_QWORD *)(a1 + 344), v5);
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL) += (int)a3;
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL) -= (int)a3;
return func1(a1);
}

original_code:
void
kogmo_rtdb_obj_mem_free (kogmo_rtdb_handle_t *db_h, kogmo_rtdb_objsize_t idx,
                         kogmo_rtdb_objsize_t size )
{
  void *ptr = db_h->localdata_p->heap + idx;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_free: %i bytes at %p", size, ptr); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  kogmo_rtdb_heap_lock(db_h);
  suba_free (db_h-> heapinfo, ptr);
  db_h->localdata_p->heap_free += size;
  db_h->localdata_p->heap_used -= size;
  kogmo_rtdb_heap_unlock(db_h);
}

canonical_original_code:
void kogmo_rtdb_obj_mem_free(struct kogmo_rtdb_handle_t *db_h, int idx, int size)
{
  void *ptr = db_h->localdata_p->heap + idx;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_free: %i bytes at %p", size, ptr); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  kogmo_rtdb_heap_lock(db_h);
  suba_free (db_h-> heapinfo, ptr);
  db_h->localdata_p->heap_free += size;
  db_h->localdata_p->heap_used -= size;
  kogmo_rtdb_heap_unlock(db_h);
}

variable_types: idx int

return_type: void

user_defined_types: struct kogmo_rtdb_handle_t { struct kogmo_rtdb_obj_info_t procobjmeta; struct kogmo_rtdb_obj_c3_process_t procobj; struct kogmo_rtdb_obj_local_t *localdata_p; long localdata_size; void *heapinfo; struct kogmo_rtdb_ipc_handle_t ipc_h; }

user_defined_types: struct kogmo_rtdb_obj_info_t { int oid; char name[32]; long created_ts; int created_proc; long lastmodified_ts; int lastmodified_proc; long deleted_ts; int deleted_proc; int parent_oid; int otype; int size_max; float history_interval; float avg_cycletime; float max_cycletime; struct { unsigned int read_deny; unsigned int write_allow; unsigned int keep_alloc; unsigned int unique; unsigned int cycle_watch; unsigned int persistent; unsigned int parent_delete; unsigned int no_notifies; unsigned int immediately_delete; unsigned int withhold_stale; } flags; int history_size; int history_slot; int buffer_idx; }

user_defined_types: struct kogmo_rtdb_obj_c3_process_t { struct kogmo_rtdb_subobj_base_t base; struct kogmo_rtdb_subobj_c3_process_t process; }

user_defined_types: struct kogmo_rtdb_ipc_handle_t { int shmfd; char shmid[32]; struct kogmo_rtdb_ipc_shm_t *shm_p; long shm_size; struct kogmo_rtdb_ipc_process_t this_process; int this_process_slot; int tracefd; int rxtracefd; }

user_defined_types: struct kogmo_rtdb_subobj_base_t { long committed_ts; int committed_proc; long data_ts; int size; }

user_defined_types: struct kogmo_rtdb_subobj_c3_process_t { int proc_oid; unsigned int pid; unsigned int tid; unsigned int flags; unsigned int status; char statusmsg[160]; unsigned int version; unsigned int uid; }

user_defined_types: struct kogmo_rtdb_obj_local_t { unsigned long objmeta_oid_next; struct kogmo_rtdb_obj_info_t objmeta[1000]; unsigned int objmeta_free; union pthread_mutex_t objmeta_lock; union pthread_cond_t objmeta_changenotify; union pthread_mutex_t obj_lock[1000]; union pthread_cond_t obj_changenotify[1000]; union pthread_mutex_t obj_changenotify_lock[1000]; int rtdb_trace; int rtdb_tracebufsize; struct { unsigned int simmode; unsigned int no_notifies; } flags; long sim_ts; float default_history_interval; float default_max_cycletime; float default_keep_deleted_interval; unsigned long heap_size; unsigned long heap_free; unsigned long heap_used; union pthread_mutex_t heap_lock; char heap[1]; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct kogmo_rtdb_ipc_shm_t { unsigned int revision; int manager_pid; long manager_alive_ts; union pthread_mutex_t global_lock; struct kogmo_rtdb_ipc_process_t proc[100]; unsigned int proc_free; union pthread_mutex_t proc_lock; unsigned long proc_oid_next; long data_size; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct kogmo_rtdb_ipc_process_t { int proc_oid; long connected_ts; long disconnected_ts; float cycletime; int pid; unsigned long tid; unsigned int flags; char name[32]; }


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_mem_init(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // r13
const void *v4; // r12
__int64 v6; // rdx
FILE *v7; // rdi
FILE *v8; // rdi
FILE *v9; // rsi

v2 = *(_QWORD *)(a1 + 328);
v3 = *(_QWORD *)(v2 + 240144);
v4 = (const void *)(v2 + 240208);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v6 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v7 = stdout;
else
v7 = stderr;
fprintf(v7, "%d DBG: ", v6);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "mem_init: %i bytes at %p", (unsigned int)v3, v4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v9 = stdout;
else
v9 = stderr;
fputc(10, v9);
}
*(_QWORD *)(a1 + 344) = suba_init(v4, (int)v3, 1LL, 1024LL);
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL) = (int)v3;
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL) = 0LL;
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // r13
const void *v4; // r12
__int64 v6; // rdx
FILE *v7; // rdi
FILE *v8; // rdi
FILE *v9; // rsi

v2 = *(_QWORD *)(a1 + 328);
v3 = *(_QWORD *)(v2 + 240144);
v4 = (const void *)(v2 + 240208);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v6 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v7 = stdout;
else
v7 = stderr;
fprintf(v7, "%d DBG: ", v6);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fprintf(v8, "mem_init: %i bytes at %p", (unsigned int)v3, v4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v9 = stdout;
else
v9 = stderr;
fputc(10, v9);
}
*(_QWORD *)(a1 + 344) = suba_init(v4, (int)v3, 1LL, 1024LL);
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL) = (int)v3;
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL) = 0LL;
return (unsigned int)v3;
}

original_code:
kogmo_rtdb_objsize_t
kogmo_rtdb_obj_mem_init (kogmo_rtdb_handle_t *db_h)
{
  kogmo_rtdb_objsize_t size = db_h->localdata_p->heap_size;
  kogmo_rtdb_objsize_t free;
  void *base = db_h->localdata_p->heap;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_init: %i bytes at %p", size, base); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  db_h->heapinfo =
    suba_init(base, size, 1 , 1024 );
  free = size;
  db_h->localdata_p->heap_free = free;
  db_h->localdata_p->heap_used = 0;
  return free;
}

canonical_original_code:
int kogmo_rtdb_obj_mem_init(struct kogmo_rtdb_handle_t *db_h)
{
  int size = db_h->localdata_p->heap_size;
  int free;
  void *base = db_h->localdata_p->heap;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_init: %i bytes at %p", size, base); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  db_h->heapinfo =
    suba_init(base, size, 1 , 1024 );
  free = size;
  db_h->localdata_p->heap_free = free;
  db_h->localdata_p->heap_used = 0;
  return free;
}

variable_types: free int

return_type: int


decompiled_code:
__int64 __fastcall kogmo_rtdb_obj_mem_attach(__int64 a1)
{
__int64 v2; // rax
const void *v3; // rbp
__int64 v5; // rdx
FILE *v6; // rdi
FILE *v7; // rdi
FILE *v8; // rsi

v2 = *(_QWORD *)(a1 + 328);
v3 = (const void *)(v2 + 240208);
*(_QWORD *)(a1 + 344) = suba_init(v2 + 240208, *(int *)(v2 + 240144), 0LL, 0LL);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v5 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v6 = stdout;
else
v6 = stderr;
fprintf(v6, "%d DBG: ", v5);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v7 = stdout;
else
v7 = stderr;
fprintf(v7, "mem_attach(suba) at %p with %p", v3, *(const void **)(a1 + 344));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fputc(10, v8);
}
return *(_QWORD *)(a1 + 344) == 0LL ? 0x16 : 0;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v2; // rax
const void *v3; // rbp
__int64 v5; // rdx
FILE *v6; // rdi
FILE *v7; // rdi
FILE *v8; // rsi

v2 = *(_QWORD *)(a1 + 328);
v3 = (const void *)(v2 + 240208);
*(_QWORD *)(a1 + 344) = suba_init(v2 + 240208, *(int *)(v2 + 240144), 0LL, 0LL);
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v5 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v6 = stdout;
else
v6 = stderr;
fprintf(v6, "%d DBG: ", v5);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v7 = stdout;
else
v7 = stderr;
fprintf(v7, "mem_attach(suba) at %p with %p", v3, *(const void **)(a1 + 344));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v8 = stdout;
else
v8 = stderr;
fputc(10, v8);
}
return *(_QWORD *)(a1 + 344) == 0LL ? 0x16 : 0;
}

original_code:
kogmo_rtdb_objsize_t
kogmo_rtdb_obj_mem_attach (kogmo_rtdb_handle_t *db_h)
{
  kogmo_rtdb_objsize_t size = db_h->localdata_p->heap_size;
  void *base = db_h->localdata_p ->heap;
  db_h->heapinfo =
    suba_init(base, size, 0 , 0);
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_attach(suba) at %p with %p",base,db_h->heapinfo); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if(db_h->heapinfo == ((void *)0)) return 22;
  return 0;
}

canonical_original_code:
int kogmo_rtdb_obj_mem_attach(struct kogmo_rtdb_handle_t *db_h)
{
  int size = db_h->localdata_p->heap_size;
  void *base = db_h->localdata_p ->heap;
  db_h->heapinfo =
    suba_init(base, size, 0 , 0);
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_attach(suba) at %p with %p",base,db_h->heapinfo); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
  if(db_h->heapinfo == ((void *)0)) return 22;
  return 0;
}


decompiled_code:
int __fastcall kogmo_rtdb_obj_mem_destroy(__int64 a1)
{
void *v1; // rax
__int64 v3; // rbp
__int64 v4; // rdx
FILE *v5; // rdi
FILE *v6; // rdi
FILE *v7; // rsi

v1 = &kogmo_rtdb_debug;
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v3 = *(_QWORD *)(a1 + 328);
v4 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v5 = stdout;
else
v5 = stderr;
fprintf(v5, "%d DBG: ", v4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v6 = stdout;
else
v6 = stderr;
fprintf(
v6,
"mem_destroy: release %p, %lli bytes were used, %lli free",
(const void *)(v3 + 240208),
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL),
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v7 = stdout;
else
v7 = stderr;
LODWORD(v1) = fputc(10, v7);
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
void *v1; // rax
__int64 v3; // rbp
__int64 v4; // rdx
FILE *v5; // rdi
FILE *v6; // rdi
FILE *v7; // rsi

v1 = &kogmo_rtdb_debug;
if ( (kogmo_rtdb_debug & 4) != 0 )
{
v3 = *(_QWORD *)(a1 + 328);
v4 = (unsigned int)getpid();
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v5 = stdout;
else
v5 = stderr;
fprintf(v5, "%d DBG: ", v4);
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v6 = stdout;
else
v6 = stderr;
fprintf(
v6,
"mem_destroy: release %p, %lli bytes were used, %lli free",
(const void *)(v3 + 240208),
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240160LL),
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 240152LL));
if ( (*(&kogmo_rtdb_debug + 1) & 1) != 0 )
v7 = stdout;
else
v7 = stderr;
LODWORD(v1) = fputc(10, v7);
}
return (int)v1;
}

original_code:
void
kogmo_rtdb_obj_mem_destroy (kogmo_rtdb_handle_t *db_h)
{
  void *base = db_h->localdata_p->heap;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_destroy: release %p, %lli bytes were used, %lli free", base, (long long int) db_h->localdata_p->heap_used, (long long int) db_h->localdata_p->heap_free); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
}

canonical_original_code:
void kogmo_rtdb_obj_mem_destroy(struct kogmo_rtdb_handle_t *db_h)
{
  void *base = db_h->localdata_p->heap;
  do { if( ( (kogmo_rtdb_debug) & (4) ) == (4) ) { fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"%d DBG: ",getpid()); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"mem_destroy: release %p, %lli bytes were used, %lli free", base, (long long) db_h->localdata_p->heap_used, (long long) db_h->localdata_p->heap_free); fprintf(((kogmo_rtdb_debug) & 256 ? stdout : stderr),"\n"); } } while (0);
}


strprintf

decompiled_code:
int strprintf(void **a1, char **a2, int *a3, const char *a4, ...)
{
int result; // eax
int v8; // eax
void *v9; // rax
char *v10; // rdi
int v11; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

result = 0;
while ( 1 )
{
if ( !result && *a1 )
goto LABEL_5;
v8 = *a3;
*a3 += 1024;
v9 = realloc(*a1, v8 + 1024);
*a1 = v9;
if ( !v9 )
return -1;
if ( !*a2 )
*a2 = (char *)v9;
LABEL_5:
v10 = *a2;
v11 = *a3 - (*(_DWORD *)a2 - *(_DWORD *)a1);
va_start(arg, a4);
result = vsnprintf(v10, v11, a4, arg);
if ( result >= 0 && v11 > result )
{
*a2 += result;
return result;
}
if ( v11 <= result )
*a3 += result;
}
}

canonical_decompiled_code:
int func0(void **a1, char **a2, int *a3, const char *a4, ...)
{
int result; // eax
int v8; // eax
void *v9; // rax
char *v10; // rdi
int v11; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-100h] BYREF

result = 0;
while ( 1 )
{
if ( !result && *a1 )
goto LABEL_5;
v8 = *a3;
*a3 += 1024;
v9 = realloc(*a1, v8 + 1024);
*a1 = v9;
if ( !v9 )
return -1;
if ( !*a2 )
*a2 = (char *)v9;
LABEL_5:
v10 = *a2;
v11 = *a3 - (*(_DWORD *)a2 - *(_DWORD *)a1);
va_start(arg, a4);
result = vsnprintf(v10, v11, a4, arg);
if ( result >= 0 && v11 > result )
{
*a2 += result;
return result;
}
if ( v11 <= result )
*a3 += result;
}
}

original_code:
int
strprintf (char **strbuf, char **strptr, int *strlen, const char *fmt, ...)
{
  va_list va;
  const int chunk = 1024;
  int strspace = 0;
  int ret = 0;
  while (1)
    {
      if ( ret != 0 || *strbuf == ((void *)0) )
        {
          *strlen += chunk;
          *strbuf = (char*)realloc (*strbuf, *strlen);
          if (*strbuf == ((void *)0))
            return -1;
          if (*strptr == ((void *)0))
            *strptr = *strbuf;
        }
      strspace = *strlen - (*strptr - *strbuf);
      __builtin_va_start(va,fmt);
      ret = vsnprintf (*strptr, strspace, fmt, va);
      __builtin_va_end(va);
      if ( ret >= 0 && ret < strspace )
        {
          *strptr += ret;
          return ret;
        }
      if ( ret >= strspace )
        *strlen += ret;
    }
}

canonical_original_code:
int strprintf(char **strbuf, char **strptr, int *strlen, char *fmt, ...)
{
  __builtin_va_list va;
  int chunk = 1024;
  int strspace = 0;
  int ret = 0;
  while (1)
    {
      if ( ret != 0 || *strbuf == ((void *)0) )
        {
          *strlen += chunk;
          *strbuf = (char *)realloc (*strbuf, *strlen);
          if (*strbuf == ((void *)0))
            return -1;
          if (*strptr == ((void *)0))
            *strptr = *strbuf;
        }
      strspace = *strlen - (*strptr - *strbuf);
      __builtin_va_start(va,fmt);
      ret = vsnprintf (*strptr, strspace, fmt, va);
      __builtin_va_end(va);
      if ( ret >= 0 && ret < strspace )
        {
          *strptr += ret;
          return ret;
        }
      if ( ret >= strspace )
        *strlen += ret;
    }
}

variable_types:
strbuf
char **

variable_types:
strptr
char **

variable_types:
strlen
int *

variable_types:
fmt
char *

variable_types: chunk int

variable_types: strspace int

variable_types: ret int


original_code:
int aviraw_initheader(avirawheader_t *avirawheader, float fps, int width, int height, int bpp)
{
  int i, nstreams, imgsize, nframes;
  nstreams = 10;
  if(!fps || !width || !height || nstreams<1 || nstreams > 10)
    return(-1);
  imgsize = width*height*(bpp/8);
  nframes = (0x7f000000) / (fps*imgsize);
  memset (avirawheader, 0, sizeof(avirawheader_t));
  avirawheader->riff_header.header_fcc[0] = 'R';
  avirawheader->riff_header.header_fcc[1] = 'I';
  avirawheader->riff_header.header_fcc[2] = 'F';
  avirawheader->riff_header.header_fcc[3] = 'F';
  avirawheader->riff_header.file_cb = sizeof(avirawheader_t) -8 + (0x7f000000);
  avirawheader->riff_header.file_fcc[0] = 'A';
  avirawheader->riff_header.file_fcc[1] = 'V';
  avirawheader->riff_header.file_fcc[2] = 'I';
  avirawheader->riff_header.file_fcc[3] = ' ';
  avirawheader->hdrl_list.list_fcc[0] = 'L';
  avirawheader->hdrl_list.list_fcc[1] = 'I';
  avirawheader->hdrl_list.list_fcc[2] = 'S';
  avirawheader->hdrl_list.list_fcc[3] = 'T';
  avirawheader->hdrl_list.list_cb = sizeof(avirawheader->hdrl_list) + sizeof(avirawheader->avih_header) +
       sizeof(avirawheader->strl_list) + sizeof(avirawheader->str_headers) - 8;
  avirawheader->hdrl_list.type_fcc[0] = 'h';
  avirawheader->hdrl_list.type_fcc[1] = 'd';
  avirawheader->hdrl_list.type_fcc[2] = 'r';
  avirawheader->hdrl_list.type_fcc[3] = 'l';
  avirawheader->avih_header.fcc[0] = 'a';
  avirawheader->avih_header.fcc[1] = 'v';
  avirawheader->avih_header.fcc[2] = 'i';
  avirawheader->avih_header.fcc[3] = 'h';
  avirawheader->avih_header.cb = sizeof(avirawheader->avih_header) - 8;
  avirawheader->avih_header.dwMicroSecPerFrame = (uint32_t)(1000000.0 / fps);
  avirawheader->avih_header.dwMaxBytesPerSec = (uint32_t)(fps*imgsize);
  avirawheader->avih_header.dwPaddingGranularity = 0;
  avirawheader->avih_header.dwFlags = 0;
  avirawheader->avih_header.dwTotalFrames = nframes;
  avirawheader->avih_header.dwInitialFrames = 0;
  avirawheader->avih_header.dwStreams = nstreams;
  avirawheader->avih_header.dwSuggestedBufferSize = width*height;
  avirawheader->avih_header.dwWidth = width;
  avirawheader->avih_header.dwHeight = height;
  avirawheader->strl_list.list_fcc[0] = 'L';
  avirawheader->strl_list.list_fcc[1] = 'I';
  avirawheader->strl_list.list_fcc[2] = 'S';
  avirawheader->strl_list.list_fcc[3] = 'T';
  avirawheader->strl_list.list_cb = sizeof(avirawheader->strl_list) + sizeof(avirawheader->str_headers) - 8;
  avirawheader->strl_list.type_fcc[0] = 's';
  avirawheader->strl_list.type_fcc[1] = 't';
  avirawheader->strl_list.type_fcc[2] = 'r';
  avirawheader->strl_list.type_fcc[3] = 'l';
  for(i=0;i<10;i++)
    {
      avirawheader->str_headers[i].strh_header.fcc[0] = 'J';
      avirawheader->str_headers[i].strh_header.fcc[1] = 'U';
      avirawheader->str_headers[i].strh_header.fcc[2] = 'N';
      avirawheader->str_headers[i].strh_header.fcc[3] = 'K';
      avirawheader->str_headers[i].strh_header.cb = sizeof(avirawheader->str_headers[0].strh_header) - 8 + sizeof(avirawheader->str_headers[0].strf_header);
    }
  avirawheader->movi_list.list_fcc[0] = 'L';
  avirawheader->movi_list.list_fcc[1] = 'I';
  avirawheader->movi_list.list_fcc[2] = 'S';
  avirawheader->movi_list.list_fcc[3] = 'T';
  avirawheader->movi_list.list_cb = sizeof(avirawheader->movi_list) - 8 + (0x7f000000);
  avirawheader->movi_list.type_fcc[0] = 'm';
  avirawheader->movi_list.type_fcc[1] = 'o';
  avirawheader->movi_list.type_fcc[2] = 'v';
  avirawheader->movi_list.type_fcc[3] = 'i';
  return 0;
}

canonical_original_code:
int aviraw_initheader(struct avirawheaderv1_t *avirawheader, float fps, int width, int height, int bpp)
{
  int i; int nstreams; int imgsize; int nframes;
  nstreams = 10;
  if(!fps || !width || !height || nstreams<1 || nstreams > 10)
    return(-1);
  imgsize = width*height*(bpp/8);
  nframes = (0x7f000000) / (fps*imgsize);
  memset (avirawheader, 0, sizeof(avirawheader_t));
  avirawheader->riff_header.header_fcc[0] = 'R';
  avirawheader->riff_header.header_fcc[1] = 'I';
  avirawheader->riff_header.header_fcc[2] = 'F';
  avirawheader->riff_header.header_fcc[3] = 'F';
  avirawheader->riff_header.file_cb = sizeof(avirawheader_t) -8 + (0x7f000000);
  avirawheader->riff_header.file_fcc[0] = 'A';
  avirawheader->riff_header.file_fcc[1] = 'V';
  avirawheader->riff_header.file_fcc[2] = 'I';
  avirawheader->riff_header.file_fcc[3] = ' ';
  avirawheader->hdrl_list.list_fcc[0] = 'L';
  avirawheader->hdrl_list.list_fcc[1] = 'I';
  avirawheader->hdrl_list.list_fcc[2] = 'S';
  avirawheader->hdrl_list.list_fcc[3] = 'T';
  avirawheader->hdrl_list.list_cb = sizeof(avirawheader->hdrl_list) + sizeof(avirawheader->avih_header) +
       sizeof(avirawheader->strl_list) + sizeof(avirawheader->str_headers) - 8;
  avirawheader->hdrl_list.type_fcc[0] = 'h';
  avirawheader->hdrl_list.type_fcc[1] = 'd';
  avirawheader->hdrl_list.type_fcc[2] = 'r';
  avirawheader->hdrl_list.type_fcc[3] = 'l';
  avirawheader->avih_header.fcc[0] = 'a';
  avirawheader->avih_header.fcc[1] = 'v';
  avirawheader->avih_header.fcc[2] = 'i';
  avirawheader->avih_header.fcc[3] = 'h';
  avirawheader->avih_header.cb = sizeof(avirawheader->avih_header) - 8;
  avirawheader->avih_header.dwMicroSecPerFrame = (unsigned int)(1000000.0 / fps);
  avirawheader->avih_header.dwMaxBytesPerSec = (unsigned int)(fps*imgsize);
  avirawheader->avih_header.dwPaddingGranularity = 0;
  avirawheader->avih_header.dwFlags = 0;
  avirawheader->avih_header.dwTotalFrames = nframes;
  avirawheader->avih_header.dwInitialFrames = 0;
  avirawheader->avih_header.dwStreams = nstreams;
  avirawheader->avih_header.dwSuggestedBufferSize = width*height;
  avirawheader->avih_header.dwWidth = width;
  avirawheader->avih_header.dwHeight = height;
  avirawheader->strl_list.list_fcc[0] = 'L';
  avirawheader->strl_list.list_fcc[1] = 'I';
  avirawheader->strl_list.list_fcc[2] = 'S';
  avirawheader->strl_list.list_fcc[3] = 'T';
  avirawheader->strl_list.list_cb = sizeof(avirawheader->strl_list) + sizeof(avirawheader->str_headers) - 8;
  avirawheader->strl_list.type_fcc[0] = 's';
  avirawheader->strl_list.type_fcc[1] = 't';
  avirawheader->strl_list.type_fcc[2] = 'r';
  avirawheader->strl_list.type_fcc[3] = 'l';
  for(i=0;i<10;i++)
    {
      avirawheader->str_headers[i].strh_header.fcc[0] = 'J';
      avirawheader->str_headers[i].strh_header.fcc[1] = 'U';
      avirawheader->str_headers[i].strh_header.fcc[2] = 'N';
      avirawheader->str_headers[i].strh_header.fcc[3] = 'K';
      avirawheader->str_headers[i].strh_header.cb = sizeof(avirawheader->str_headers[0].strh_header) - 8 + sizeof(avirawheader->str_headers[0].strf_header);
    }
  avirawheader->movi_list.list_fcc[0] = 'L';
  avirawheader->movi_list.list_fcc[1] = 'I';
  avirawheader->movi_list.list_fcc[2] = 'S';
  avirawheader->movi_list.list_fcc[3] = 'T';
  avirawheader->movi_list.list_cb = sizeof(avirawheader->movi_list) - 8 + (0x7f000000);
  avirawheader->movi_list.type_fcc[0] = 'm';
  avirawheader->movi_list.type_fcc[1] = 'o';
  avirawheader->movi_list.type_fcc[2] = 'v';
  avirawheader->movi_list.type_fcc[3] = 'i';
  return 0;
}

variable_types: struct avirawheaderv1_t { struct riffheader_t { char header_fcc[4]; unsigned int file_cb; char file_fcc[4]; } riff_header; struct rifflist_t { char list_fcc[4]; unsigned int list_cb; char type_fcc[4]; } hdrl_list; struct avimainheader_t { char fcc[4]; unsigned int cb; unsigned int dwMicroSecPerFrame; unsigned int dwMaxBytesPerSec; unsigned int dwPaddingGranularity; unsigned int dwFlags; unsigned int dwTotalFrames; unsigned int dwInitialFrames; unsigned int dwStreams; unsigned int dwSuggestedBufferSize; unsigned int dwWidth; unsigned int dwHeight; unsigned int dwReserved[4]; } avih_header; struct rifflist_t strl_list; struct { struct avistreamheader_t { char fcc[4]; unsigned int cb; char fccType[4]; char fccHandler[4]; unsigned int dwFlags; unsigned short wPriority; unsigned short wLanguage; unsigned int dwInitialFrames; unsigned int dwScale; unsigned int dwRate; unsigned int dwStart; unsigned int dwLength; unsigned int dwSuggestedBufferSize; unsigned int dwQuality; unsigned int dwSampleSize; struct { unsigned short left; unsigned short top; unsigned short right; unsigned short bottom; } rcFrame; } strh_header; struct avibitmapheader_t { char fcc[4]; unsigned int cb; unsigned int biSize; int biWidth; int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; int biXPelsPerMeter; int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; struct rgbquad_t { unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved; } bmiColors[256]; } strf_header; } str_headers[10]; struct rifflist_t movi_list; } *

variable_types: fps float

variable_types: width int

variable_types: height int

variable_types: bpp int

variable_types: i int

variable_types: nstreams int

variable_types: imgsize int

variable_types: nframes int

user_defined_types: struct avirawheaderv1_t { struct riffheader_t riff_header; struct rifflist_t hdrl_list; struct avimainheader_t avih_header; struct rifflist_t strl_list; struct { struct avistreamheader_t strh_header; struct avibitmapheader_t strf_header; } str_headers[10]; struct rifflist_t movi_list; }

user_defined_types: struct avibitmapheader_t { char fcc[4]; unsigned int cb; unsigned int biSize; int biWidth; int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; int biXPelsPerMeter; int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; struct rgbquad_t bmiColors[256]; }


original_code:
int aviraw_initstream(avirawheader_t *avirawheader, int stream, float fps, int width, int height, int bpp, uint32_t compression_fourcc)
{
  int imgsize, nframes, j;
  if(!fps || !width || !height || stream<0 || stream > 10)
    return(-1);
  imgsize = width*height*(bpp/8);
  nframes = (0x7f000000) / (fps*imgsize);
  avirawheader->str_headers[stream].strh_header.fcc[0] = 's';
  avirawheader->str_headers[stream].strh_header.fcc[1] = 't';
  avirawheader->str_headers[stream].strh_header.fcc[2] = 'r';
  avirawheader->str_headers[stream].strh_header.fcc[3] = 'h';
  avirawheader->str_headers[stream].strh_header.cb = sizeof(avirawheader->str_headers[0].strh_header) - 8;
  avirawheader->str_headers[stream].strh_header.fccType[0] = 'v';
  avirawheader->str_headers[stream].strh_header.fccType[1] = 'i';
  avirawheader->str_headers[stream].strh_header.fccType[2] = 'd';
  avirawheader->str_headers[stream].strh_header.fccType[3] = 's';
  avirawheader->str_headers[stream].strh_header.fccHandler[0] = 'D';
  avirawheader->str_headers[stream].strh_header.fccHandler[1] = 'I';
  avirawheader->str_headers[stream].strh_header.fccHandler[2] = 'B';
  avirawheader->str_headers[stream].strh_header.fccHandler[3] = ' ';
  avirawheader->str_headers[stream].strh_header.dwFlags = 0;
  avirawheader->str_headers[stream].strh_header.wPriority = 0;
  avirawheader->str_headers[stream].strh_header.wLanguage = 0;
  avirawheader->str_headers[stream].strh_header.dwInitialFrames = 0;
  avirawheader->str_headers[stream].strh_header.dwScale = 1;
  avirawheader->str_headers[stream].strh_header.dwRate = (uint32_t)fps;
  avirawheader->str_headers[stream].strh_header.dwStart = 0;
  avirawheader->str_headers[stream].strh_header.dwLength = nframes;
  avirawheader->str_headers[stream].strh_header.dwSuggestedBufferSize = imgsize;
  avirawheader->str_headers[stream].strh_header.dwQuality = 0;
  avirawheader->str_headers[stream].strh_header.dwSampleSize = 0;
  avirawheader->str_headers[stream].strh_header.rcFrame.left = 0;
  avirawheader->str_headers[stream].strh_header.rcFrame.top = 0;
  avirawheader->str_headers[stream].strh_header.rcFrame.right = width;
  avirawheader->str_headers[stream].strh_header.rcFrame.bottom = height;
  avirawheader->str_headers[stream].strf_header.fcc[0] = 's';
  avirawheader->str_headers[stream].strf_header.fcc[1] = 't';
  avirawheader->str_headers[stream].strf_header.fcc[2] = 'r';
  avirawheader->str_headers[stream].strf_header.fcc[3] = 'f';
  avirawheader->str_headers[stream].strf_header.cb = sizeof(avirawheader->str_headers[0].strf_header) - 8;
  avirawheader->str_headers[stream].strf_header.biSize = sizeof(avibitmapheader_t) -8 - 256*sizeof(rgbquad_t);
  avirawheader->str_headers[stream].strf_header.biWidth = width;
  avirawheader->str_headers[stream].strf_header.biHeight = height;
  avirawheader->str_headers[stream].strf_header.biPlanes = 1;
  avirawheader->str_headers[stream].strf_header.biBitCount = bpp;
  avirawheader->str_headers[stream].strf_header.biCompression = compression_fourcc;
  avirawheader->str_headers[stream].strf_header.biSizeImage = imgsize;
  avirawheader->str_headers[stream].strf_header.biXPelsPerMeter = 0;
  avirawheader->str_headers[stream].strf_header.biYPelsPerMeter = 0;
  avirawheader->str_headers[stream].strf_header.biClrUsed = 256;
  avirawheader->str_headers[stream].strf_header.biClrImportant = 0;
  if (bpp==8)
    {
      for(j=0;j<256;j++)
        {
          avirawheader->str_headers[stream].strf_header.bmiColors[j].rgbBlue = j;
          avirawheader->str_headers[stream].strf_header.bmiColors[j].rgbGreen = j;
          avirawheader->str_headers[stream].strf_header.bmiColors[j].rgbRed = j;
        }
    }
  else
    {
      riffchunk_t *junk = (riffchunk_t*) &(avirawheader->str_headers[stream].strf_header.bmiColors[0]);
      junk->fcc[0] = 'J';
      junk->fcc[1] = 'U';
      junk->fcc[2] = 'N';
      junk->fcc[3] = 'K';
      junk->cb = 256*sizeof(rgbquad_t) - 8;
      avirawheader->str_headers[stream].strf_header.cb = sizeof(avirawheader->str_headers[0].strf_header) - 8 - 256*sizeof(rgbquad_t);
      avirawheader->str_headers[stream].strf_header.biClrUsed = 0;
    }
  return 0;
}

canonical_original_code:
int aviraw_initstream(struct avirawheaderv1_t *avirawheader, int stream, float fps, int width, int height, int bpp, unsigned int compression_fourcc)
{
  int imgsize; int nframes; int j;
  if(!fps || !width || !height || stream<0 || stream > 10)
    return(-1);
  imgsize = width*height*(bpp/8);
  nframes = (0x7f000000) / (fps*imgsize);
  avirawheader->str_headers[stream].strh_header.fcc[0] = 's';
  avirawheader->str_headers[stream].strh_header.fcc[1] = 't';
  avirawheader->str_headers[stream].strh_header.fcc[2] = 'r';
  avirawheader->str_headers[stream].strh_header.fcc[3] = 'h';
  avirawheader->str_headers[stream].strh_header.cb = sizeof(avirawheader->str_headers[0].strh_header) - 8;
  avirawheader->str_headers[stream].strh_header.fccType[0] = 'v';
  avirawheader->str_headers[stream].strh_header.fccType[1] = 'i';
  avirawheader->str_headers[stream].strh_header.fccType[2] = 'd';
  avirawheader->str_headers[stream].strh_header.fccType[3] = 's';
  avirawheader->str_headers[stream].strh_header.fccHandler[0] = 'D';
  avirawheader->str_headers[stream].strh_header.fccHandler[1] = 'I';
  avirawheader->str_headers[stream].strh_header.fccHandler[2] = 'B';
  avirawheader->str_headers[stream].strh_header.fccHandler[3] = ' ';
  avirawheader->str_headers[stream].strh_header.dwFlags = 0;
  avirawheader->str_headers[stream].strh_header.wPriority = 0;
  avirawheader->str_headers[stream].strh_header.wLanguage = 0;
  avirawheader->str_headers[stream].strh_header.dwInitialFrames = 0;
  avirawheader->str_headers[stream].strh_header.dwScale = 1;
  avirawheader->str_headers[stream].strh_header.dwRate = (unsigned int)fps;
  avirawheader->str_headers[stream].strh_header.dwStart = 0;
  avirawheader->str_headers[stream].strh_header.dwLength = nframes;
  avirawheader->str_headers[stream].strh_header.dwSuggestedBufferSize = imgsize;
  avirawheader->str_headers[stream].strh_header.dwQuality = 0;
  avirawheader->str_headers[stream].strh_header.dwSampleSize = 0;
  avirawheader->str_headers[stream].strh_header.rcFrame.left = 0;
  avirawheader->str_headers[stream].strh_header.rcFrame.top = 0;
  avirawheader->str_headers[stream].strh_header.rcFrame.right = width;
  avirawheader->str_headers[stream].strh_header.rcFrame.bottom = height;
  avirawheader->str_headers[stream].strf_header.fcc[0] = 's';
  avirawheader->str_headers[stream].strf_header.fcc[1] = 't';
  avirawheader->str_headers[stream].strf_header.fcc[2] = 'r';
  avirawheader->str_headers[stream].strf_header.fcc[3] = 'f';
  avirawheader->str_headers[stream].strf_header.cb = sizeof(avirawheader->str_headers[0].strf_header) - 8;
  avirawheader->str_headers[stream].strf_header.biSize = sizeof(avibitmapheader_t) -8 - 256*sizeof(rgbquad_t);
  avirawheader->str_headers[stream].strf_header.biWidth = width;
  avirawheader->str_headers[stream].strf_header.biHeight = height;
  avirawheader->str_headers[stream].strf_header.biPlanes = 1;
  avirawheader->str_headers[stream].strf_header.biBitCount = bpp;
  avirawheader->str_headers[stream].strf_header.biCompression = compression_fourcc;
  avirawheader->str_headers[stream].strf_header.biSizeImage = imgsize;
  avirawheader->str_headers[stream].strf_header.biXPelsPerMeter = 0;
  avirawheader->str_headers[stream].strf_header.biYPelsPerMeter = 0;
  avirawheader->str_headers[stream].strf_header.biClrUsed = 256;
  avirawheader->str_headers[stream].strf_header.biClrImportant = 0;
  if (bpp==8)
    {
      for(j=0;j<256;j++)
        {
          avirawheader->str_headers[stream].strf_header.bmiColors[j].rgbBlue = j;
          avirawheader->str_headers[stream].strf_header.bmiColors[j].rgbGreen = j;
          avirawheader->str_headers[stream].strf_header.bmiColors[j].rgbRed = j;
        }
    }
  else
    {
      struct riffchunk_t *junk = (riffchunk_t*) &(avirawheader->str_headers[stream].strf_header.bmiColors[0]);
      junk->fcc[0] = 'J';
      junk->fcc[1] = 'U';
      junk->fcc[2] = 'N';
      junk->fcc[3] = 'K';
      junk->cb = 256*sizeof(rgbquad_t) - 8;
      avirawheader->str_headers[stream].strf_header.cb = sizeof(avirawheader->str_headers[0].strf_header) - 8 - 256*sizeof(rgbquad_t);
      avirawheader->str_headers[stream].strf_header.biClrUsed = 0;
    }
  return 0;
}

variable_types: stream int

variable_types: j int

variable_types: struct riffchunk_t { char fcc[4]; unsigned int cb; } *

user_defined_types: struct riffheader_t { char header_fcc[4]; unsigned int file_cb; char file_fcc[4]; }

user_defined_types: struct rifflist_t { char list_fcc[4]; unsigned int list_cb; char type_fcc[4]; }

user_defined_types: struct avimainheader_t { char fcc[4]; unsigned int cb; unsigned int dwMicroSecPerFrame; unsigned int dwMaxBytesPerSec; unsigned int dwPaddingGranularity; unsigned int dwFlags; unsigned int dwTotalFrames; unsigned int dwInitialFrames; unsigned int dwStreams; unsigned int dwSuggestedBufferSize; unsigned int dwWidth; unsigned int dwHeight; unsigned int dwReserved[4]; }

user_defined_types: struct avistreamheader_t { char fcc[4]; unsigned int cb; char fccType[4]; char fccHandler[4]; unsigned int dwFlags; unsigned short wPriority; unsigned short wLanguage; unsigned int dwInitialFrames; unsigned int dwScale; unsigned int dwRate; unsigned int dwStart; unsigned int dwLength; unsigned int dwSuggestedBufferSize; unsigned int dwQuality; unsigned int dwSampleSize; struct { unsigned short left; unsigned short top; unsigned short right; unsigned short bottom; } rcFrame; }

user_defined_types: struct rgbquad_t { unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved; }


decompiled_code:
_BOOL8 __fastcall aviraw_chunk_is_junk(const void *a1)
{
return memcmp(a1, "JUNK", 4uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(const void *a1)
{
return memcmp(a1, "JUNK", 4uLL) == 0;
}

original_code:
int aviraw_chunk_is_junk(riffchunk_t *datachunk_p)
{
  if (strncmp (datachunk_p->fcc, "JUNK", 4) != 0)
    return 0;
  return 1;
}

canonical_original_code:
int aviraw_chunk_is_junk(struct riffchunk_t *datachunk_p)
{
  if (strncmp (datachunk_p->fcc, "JUNK", 4) != 0)
    return 0;
  return 1;
}

user_defined_types: struct riffchunk_t { char fcc[4]; unsigned int cb; }


decompiled_code:
__int64 __fastcall aviraw_chunk_nr_stream(_BYTE *a1)
{
char v1; // al

if ( *a1 != 48 )
return 0xFFFFFFFFLL;
v1 = a1[1];
if ( (unsigned __int8)(v1 - 48) > 9u )
return 0xFFFFFFFFLL;
if ( a1[2] != 100 )
return 0xFFFFFFFFLL;
if ( a1[3] == 98 )
return (unsigned int)(v1 - 48);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_BYTE *a1)
{
char v1; // al

if ( *a1 != 48 )
return 0xFFFFFFFFLL;
v1 = a1[1];
if ( (unsigned __int8)(v1 - 48) > 9u )
return 0xFFFFFFFFLL;
if ( a1[2] != 100 )
return 0xFFFFFFFFLL;
if ( a1[3] == 98 )
return (unsigned int)(v1 - 48);
return 0xFFFFFFFFLL;
}

original_code:
int aviraw_chunk_nr_stream(riffchunk_t *datachunk_p)
{
  if (datachunk_p->fcc[0] != '0') return -1;
  if (datachunk_p->fcc[1] < '0' || datachunk_p->fcc[1] > '9' ) return -1;
  if (datachunk_p->fcc[2] != 'd') return -1;
  if (datachunk_p->fcc[3] != 'b') return -1;
  return datachunk_p->fcc[1] - '0';
}

canonical_original_code:
int aviraw_chunk_nr_stream(struct riffchunk_t *datachunk_p)
{
  if (datachunk_p->fcc[0] != '0') return -1;
  if (datachunk_p->fcc[1] < '0' || datachunk_p->fcc[1] > '9' ) return -1;
  if (datachunk_p->fcc[2] != 'd') return -1;
  if (datachunk_p->fcc[3] != 'b') return -1;
  return datachunk_p->fcc[1] - '0';
}


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

if ( !a1 || !a2 )
return 0LL;
result = 0LL;
if ( *(_QWORD *)(a1 + 24) >= a2 )
result = a1 + a2;
return result;
}

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

if ( !a1 || !a2 )
return 0LL;
result = 0LL;
if ( *(_QWORD *)(a1 + 24) >= a2 )
result = a1 + a2;
return result;
}

original_code:
void *
suba_addr(const struct allocator *suba, const ref_t ref)
{
    if (suba && ref > 0 && ref <= suba->size) {
        return (char *)suba + ref;
    }
    return ((void *)0);
}

canonical_original_code:
void *suba_addr(struct allocator *suba, unsigned long ref)
{
    if (suba && ref > 0 && ref <= suba->size) {
        return (char *)suba + ref;
    }
    return ((void *)0);
}

variable_types: struct allocator { unsigned char magic[8]; unsigned long tail; unsigned long mincell; unsigned long size; unsigned long alloc_total; unsigned long free_total; unsigned long size_total; unsigned long max_free; void *(*alloc)(struct allocator *al, unsigned long size, int flags); void *(*realloc)(struct allocator *al, void *obj, unsigned long size); int (*free)(void *al, void *obj); int (*reclaim)(struct allocator *al, void *arg, int attempt); void *reclaim_arg; int reclaim_depth; unsigned long userref; } *

variable_types:
ref
unsigned long

return_type: void *


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

if ( !a1 || !a2 )
return 0LL;
result = a2 - a1;
if ( a2 != a1 && *(_QWORD *)(a1 + 24) < result )
result = 0LL;
return result;
}

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

if ( !a1 || !a2 )
return 0LL;
result = a2 - a1;
if ( a2 != a1 && *(_QWORD *)(a1 + 24) < result )
result = 0LL;
return result;
}

original_code:
ref_t
suba_ref(const struct allocator *suba, const void *ptr)
{
    if (suba && ptr) {
        ref_t ref = (char *)ptr - (char *)suba;
        if (ref > 0 && ref <= suba->size) {
            return ref;
        }
    }
    return 0;
}

canonical_original_code:
unsigned long suba_ref(struct allocator *suba, void *ptr)
{
    if (suba && ptr) {
        unsigned long ref = (char *)ptr - (char *)suba;
        if (ref > 0 && ref <= suba->size) {
            return ref;
        }
    }
    return 0;
}

variable_types:
ptr
void *

return_type: unsigned long

user_defined_types: struct allocator { unsigned char magic[8]; unsigned long tail; unsigned long mincell; unsigned long size; unsigned long alloc_total; unsigned long free_total; unsigned long size_total; unsigned long max_free; void *(*alloc)(struct allocator *al, unsigned long size, int flags); void *(*realloc)(struct allocator *al, void *obj, unsigned long size); int (*free)(void *al, void *obj); int (*reclaim)(struct allocator *al, void *arg, int attempt); void *reclaim_arg; int reclaim_depth; unsigned long userref; }


repo: matja/bitcoin-tool

decompiled_code:
__int64 __fastcall Bitcoin_DecodeHexChar(_BYTE *a1, char a2)
{
__int64 result; // rax

if ( (unsigned __int8)(a2 - 48) <= 9u )
{
*a1 = a2 - 48;
result = 1LL;
}
else if ( (unsigned __int8)(a2 - 65) <= 5u )
{
*a1 = a2 - 55;
result = 1LL;
}
else
{
result = 0LL;
if ( (unsigned __int8)(a2 - 97) <= 5u )
{
*a1 = a2 - 87;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, char a2)
{
__int64 result; // rax

if ( (unsigned __int8)(a2 - 48) <= 9u )
{
*a1 = a2 - 48;
result = 1LL;
}
else if ( (unsigned __int8)(a2 - 65) <= 5u )
{
*a1 = a2 - 55;
result = 1LL;
}
else
{
result = 0LL;
if ( (unsigned __int8)(a2 - 97) <= 5u )
{
*a1 = a2 - 87;
result = 1LL;
}
}
return result;
}

original_code:
int Bitcoin_DecodeHexChar(uint_fast8_t *output, char c)
{
 if (c >= '0' && c <= '9') {
  *output = c - '0';
  return 1;
 } else if (c >= 'A' && c <= 'F') {
  *output = c - 'A' + 10;
  return 1;
 } else if (c >= 'a' && c <= 'f') {
  *output = c - 'a' + 10;
  return 1;
 }
 return 0;
}

canonical_original_code:
int Bitcoin_DecodeHexChar(unsigned char *output, char c)
{
 if (c >= '0' && c <= '9') {
  *output = c - '0';
  return 1;
 } else if (c >= 'A' && c <= 'F') {
  *output = c - 'A' + 10;
  return 1;
 } else if (c >= 'a' && c <= 'f') {
  *output = c - 'a' + 10;
  return 1;
 }
 return 0;
}

variable_types:
output
unsigned char *

variable_types: c char


decompiled_code:
__int64 __fastcall Bitcoin_DecodeHex(_BYTE *a1, __int64 a2, _QWORD *a3, char *a4, __int64 a5)
{
char *v7; // r13
char *v9; // rbx
char v11; // [rsp+0h] [rbp-2Ah] BYREF
char v12[41]; // [rsp+1h] [rbp-29h] BYREF

*a3 = 0LL;
if ( !a5 )
return 0LL;
v7 = a4;
v9 = a4;
while ( 1 )
{
if ( !(unsigned int)Bitcoin_DecodeHexChar(&v11, *v9) )
{
applog(4LL, "Bitcoin_DecodeHex", "Invalid character (ASCII=%u) at offset %u", (unsigned int)*v9, v9 - v7);
return 7LL;
}
if ( !(unsigned int)Bitcoin_DecodeHexChar(v12, v9[1]) )
break;
v9 += 2;
*a1++ = v12[0] | (16 * v11);
++*a3;
if ( v9 == &v7[a5] )
return 0LL;
}
applog(4LL, "Bitcoin_DecodeHex", "Invalid character (ASCII=%u) at offset %u", (unsigned int)v9[1], v9 + 1 - v7);
return 7LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2, _QWORD *a3, char *a4, __int64 a5)
{
char *v7; // r13
char *v9; // rbx
char v11; // [rsp+0h] [rbp-2Ah] BYREF
char v12[41]; // [rsp+1h] [rbp-29h] BYREF

*a3 = 0LL;
if ( !a5 )
return 0LL;
v7 = a4;
v9 = a4;
while ( 1 )
{
if ( !(unsigned int)func0(&v11, *v9) )
{
applog(4LL, "Bitcoin_DecodeHex", "Invalid character (ASCII=%u) at offset %u", (unsigned int)*v9, v9 - v7);
return 7LL;
}
if ( !(unsigned int)func0(v12, v9[1]) )
break;
v9 += 2;
*a1++ = v12[0] | (16 * v11);
++*a3;
if ( v9 == &v7[a5] )
return 0LL;
}
applog(4LL, "Bitcoin_DecodeHex", "Invalid character (ASCII=%u) at offset %u", (unsigned int)v9[1], v9 + 1 - v7);
return 7LL;
}

original_code:
BitcoinResult Bitcoin_DecodeHex(void *output, size_t output_size,
 size_t *decoded_output_size,
 const char *source, size_t source_size
)
{
 unsigned char *output_bytes = (unsigned char *)output;
 const char *source_copy = source;
 *decoded_output_size = 0;
 while (source_size) {
  uint_fast8_t high, low;
  if (!Bitcoin_DecodeHexChar(&high, *source)) {
   applog(APPLOG_ERROR, __func__,
    "Invalid character (ASCII=%u) at offset %u",
    (unsigned)*source, source - source_copy
   );
   return BITCOIN_ERROR_INVALID_FORMAT;
  }
  source++;
  if (!Bitcoin_DecodeHexChar(&low, *source)) {
   applog(APPLOG_ERROR, __func__,
    "Invalid character (ASCII=%u) at offset %u",
    (unsigned)*source, source - source_copy
   );
   return BITCOIN_ERROR_INVALID_FORMAT;
  }
  source++;
  *output_bytes++ = (high << 4) | low;
  source_size -= 2;
  (*decoded_output_size)++;
 }
 return BITCOIN_SUCCESS;
}

canonical_original_code:
enum BitcoinResult Bitcoin_DecodeHex(void *output, unsigned long output_size, unsigned long *decoded_output_size, char *source, unsigned long source_size)
{
 unsigned char *output_bytes = (unsigned char *)output;
 char *source_copy = source;
 *decoded_output_size = 0;
 while (source_size) {
  unsigned char high; unsigned char low;
  if (!Bitcoin_DecodeHexChar(&high, *source)) {
   applog(APPLOG_ERROR, __func__,
    "Invalid character (ASCII=%u) at offset %u",
    (unsigned int)*source, source - source_copy
   );
   return BITCOIN_ERROR_INVALID_FORMAT;
  }
  source++;
  if (!Bitcoin_DecodeHexChar(&low, *source)) {
   applog(APPLOG_ERROR, __func__,
    "Invalid character (ASCII=%u) at offset %u",
    (unsigned int)*source, source - source_copy
   );
   return BITCOIN_ERROR_INVALID_FORMAT;
  }
  source++;
  *output_bytes++ = (high << 4) | low;
  source_size -= 2;
  (*decoded_output_size)++;
 }
 return BITCOIN_SUCCESS;
}

variable_types:
output
void *

variable_types:
source
char *

variable_types:
high
unsigned char

variable_types:
low
unsigned char

return_type: enum BitcoinResult { BITCOIN_SUCCESS=0, BITCOIN_ERROR=1, BITCOIN_ERROR_NOT_IMPLEMENTED=2, BITCOIN_ERROR_PRIVATE_KEY_INVALID_FORMAT=3, BITCOIN_ERROR_PUBLIC_KEY_INVALID_FORMAT=4, BITCOIN_ERROR_OUTPUT_BUFFER_TOO_SMALL=5, BITCOIN_ERROR_CHECKSUM_FAILURE=6, BITCOIN_ERROR_INVALID_FORMAT=7, BITCOIN_ERROR_IMPOSSIBLE_CONVERSION=8, BITCOIN_ERROR_FILE=9, BITCOIN_ERROR_LIBRARY_FAILURE=10, BITCOIN_ERROR_END_OF_FILE=11 }


original_code:
BitcoinResult Bitcoin_EncodeHex(
 char *output, size_t output_size,
 size_t *encoded_output_size,
 const void *source, size_t source_size,
 int lower_case
)
{
 static const char hex_chars_lower[] = "0123456789abcdef";
 static const char hex_chars_upper[] = "0123456789ABCDEF";
 const uint8_t *source_bytes = (const uint8_t *)source;
 const char *hex_chars = lower_case ? hex_chars_lower : hex_chars_upper;
 size_t output_bytes_left = output_size;
 *encoded_output_size = 0;
 while (source_size-- && output_bytes_left >= 2) {
  output[0] = hex_chars[(*source_bytes >> 4) & 0xf];
  output[1] = hex_chars[(*source_bytes) & 0xf];
  output += 2;
  *encoded_output_size += 2;
  output_bytes_left -= 2;
  source_bytes++;
 }
 return BITCOIN_SUCCESS;
}

canonical_original_code:
enum BitcoinResult Bitcoin_EncodeHex(char *output, unsigned long output_size, unsigned long *encoded_output_size, void *source, unsigned long source_size, int lower_case)
{
 static char hex_chars_lower[] = "0123456789abcdef";
 static char hex_chars_upper[] = "0123456789ABCDEF";
 unsigned char *source_bytes = (const uint8_t *)source;
 char *hex_chars = lower_case ? hex_chars_lower : hex_chars_upper;
 unsigned long output_bytes_left = output_size;
 *encoded_output_size = 0;
 while (source_size-- && output_bytes_left >= 2) {
  output[0] = hex_chars[(*source_bytes >> 4) & 0xf];
  output[1] = hex_chars[(*source_bytes) & 0xf];
  output += 2;
  *encoded_output_size += 2;
  output_bytes_left -= 2;
  source_bytes++;
 }
 return BITCOIN_SUCCESS;
}

variable_types:
output
char *

variable_types:
source
void *

user_defined_types: enum BitcoinResult { BITCOIN_SUCCESS=0, BITCOIN_ERROR=1, BITCOIN_ERROR_NOT_IMPLEMENTED=2, BITCOIN_ERROR_PRIVATE_KEY_INVALID_FORMAT=3, BITCOIN_ERROR_PUBLIC_KEY_INVALID_FORMAT=4, BITCOIN_ERROR_OUTPUT_BUFFER_TOO_SMALL=5, BITCOIN_ERROR_CHECKSUM_FAILURE=6, BITCOIN_ERROR_INVALID_FORMAT=7, BITCOIN_ERROR_IMPOSSIBLE_CONVERSION=8, BITCOIN_ERROR_FILE=9, BITCOIN_ERROR_LIBRARY_FAILURE=10, BITCOIN_ERROR_END_OF_FILE=11 }


decompiled_code:
int __fastcall Bitcoin_OutputHex(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
int result; // eax

if ( a2 )
{
v2 = a1;
do
result = printf("%02x", *v2++);
while ( &a1[a2] != v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
int result; // eax

if ( a2 )
{
v2 = a1;
do
result = printf("%02x", *v2++);
while ( &a1[a2] != v2 );
}
return result;
}

original_code:
void Bitcoin_OutputHex(const void *source, size_t source_size)
{
 const uint8_t *source_bytes = (const uint8_t *)source;
 while (source_size--) {
  printf("%02x", *source_bytes++);
 }
}

canonical_original_code:
void Bitcoin_OutputHex(void *source, unsigned long source_size)
{
 unsigned char *source_bytes = (const uint8_t *)source;
 while (source_size--) {
  printf("%02x", *source_bytes++);
 }
}


original_code:
static int convert_bits(uint8_t* out, size_t* outlen, int outbits, const uint8_t* in, size_t inlen, int inbits, int pad) {
    uint32_t val = 0;
    int bits = 0;
    uint32_t maxv = (((uint32_t)1) << outbits) - 1;
    while (inlen--) {
        val = (val << inbits) | *(in++);
        bits += inbits;
        while (bits >= outbits) {
            bits -= outbits;
            out[(*outlen)++] = (val >> bits) & maxv;
        }
    }
    if (pad) {
        if (bits) {
            out[(*outlen)++] = (val << (outbits - bits)) & maxv;
        }
    } else if (((val << (outbits - bits)) & maxv) || bits >= inbits) {
        return 0;
    }
    return 1;
}

canonical_original_code:
static int convert_bits(unsigned char *out, unsigned long *outlen, int outbits, unsigned char *in, unsigned long inlen, int inbits, int pad) {
    unsigned int val = 0;
    int bits = 0;
    unsigned int maxv = (((uint32_t)1) << outbits) - 1;
    while (inlen--) {
        val = (val << inbits) | *(in++);
        bits += inbits;
        while (bits >= outbits) {
            bits -= outbits;
            out[(*outlen)++] = (val >> bits) & maxv;
        }
    }
    if (pad) {
        if (bits) {
            out[(*outlen)++] = (val << (outbits - bits)) & maxv;
        }
    } else if (((val << (outbits - bits)) & maxv) || bits >= inbits) {
        return 0;
    }
    return 1;
}

variable_types:
out
unsigned char *

variable_types:
outlen
unsigned long *

variable_types: outbits int

variable_types:
in
unsigned char *

variable_types:
inlen
unsigned long

variable_types: inbits int

variable_types: pad int

variable_types:
val
unsigned int

variable_types: bits int

variable_types:
maxv
unsigned int


variable_types:
pre
unsigned int

variable_types:
b
unsigned char

return_type: unsigned int


decompiled_code:
__int64 __fastcall bech32_encode(_BYTE *a1, char *a2, unsigned __int8 *a3, __int64 a4)
{
char v6; // r13
char *v7; // r12
char v8; // bl
__int64 v9; // rbp
unsigned int v10; // edi
__int64 result; // rax
unsigned int v12; // edi
_BYTE *v13; // rbx
__int64 v14; // rbp
unsigned __int8 v15; // r12
__int64 v16; // rbx
unsigned int v17; // eax
unsigned int v18; // eax
_BYTE *v19; // rsi
int i; // ecx

v6 = *a2;
if ( *a2 )
{
v7 = a2;
v8 = *a2;
v9 = 0LL;
v10 = 1;
while ( 1 )
{
if ( (unsigned int)(v8 - 33) > 0x5D )
return 0LL;
if ( (unsigned int)(v8 - 65) <= 0x19 )
return 0LL;
v10 = bech32_polymod_step(v10) ^ (v8 >> 5);
v8 = a2[v9 + 1];
if ( !v8 )
break;
++v9;
}
result = 0LL;
if ( (unsigned __int64)(v9 + a4 + 8) > 0x5A )
return result;
v12 = bech32_polymod_step(v10);
do
{
v12 = v6 & 0x1F ^ bech32_polymod_step(v12);
++v7;
*a1++ = v6;
v6 = *v7;
}
while ( *v7 );
}
else
{
result = 0LL;
if ( (unsigned __int64)(a4 + 7) > 0x5A )
return result;
v12 = bech32_polymod_step(1u);
}
v13 = a1 + 1;
*a1 = 49;
if ( a4 )
{
v14 = (__int64)&a1[a4 + 1];
while ( 1 )
{
v15 = *a3;
if ( *a3 >> 5 )
break;
v12 = v15 ^ (unsigned int)bech32_polymod_step(v12);
++a3;
*v13++ = byte_6A8[v15];
if ( v13 == (_BYTE *)v14 )
goto LABEL_14;
}
result = 0LL;
}
else
{
v14 = (__int64)(a1 + 1);
LABEL_14:
v16 = 6LL;
do
{
v17 = bech32_polymod_step(v12);
v12 = v17;
--v16;
}
while ( v16 );
v18 = v17 ^ 1;
v19 = (_BYTE *)v14;
for ( i = 25; i != -5; i -= 5 )
*v19++ = byte_6A8[(v18 >> i) & 0x1F];
*(_BYTE *)(v14 + 6) = 0;
result = 1LL;
}
return result;
}

original_code:
int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t data_len) {
    uint32_t chk = 1;
    size_t i = 0;
    while (hrp[i] != 0) {
        int ch = hrp[i];
        if (ch < 33 || ch > 126) {
            return 0;
        }
        if (ch >= 'A' && ch <= 'Z') return 0;
        chk = bech32_polymod_step(chk) ^ (ch >> 5);
        ++i;
    }
    if (i + 7 + data_len > 90) return 0;
    chk = bech32_polymod_step(chk);
    while (*hrp != 0) {
        chk = bech32_polymod_step(chk) ^ (*hrp & 0x1f);
        *(output++) = *(hrp++);
    }
    *(output++) = '1';
    for (i = 0; i < data_len; ++i) {
        if (*data >> 5) return 0;
        chk = bech32_polymod_step(chk) ^ (*data);
        *(output++) = charset[*(data++)];
    }
    for (i = 0; i < 6; ++i) {
        chk = bech32_polymod_step(chk);
    }
    chk ^= 1;
    for (i = 0; i < 6; ++i) {
        *(output++) = charset[(chk >> ((5 - i) * 5)) & 0x1f];
    }
    *output = 0;
    return 1;
}

canonical_original_code:
int bech32_encode(char *output, char *hrp, unsigned char *data, unsigned long data_len) {
    unsigned int chk = 1;
    unsigned long i = 0;
    while (hrp[i] != 0) {
        int ch = hrp[i];
        if (ch < 33 || ch > 126) {
            return 0;
        }
        if (ch >= 'A' && ch <= 'Z') return 0;
        chk = bech32_polymod_step(chk) ^ (ch >> 5);
        ++i;
    }
    if (i + 7 + data_len > 90) return 0;
    chk = bech32_polymod_step(chk);
    while (*hrp != 0) {
        chk = bech32_polymod_step(chk) ^ (*hrp & 0x1f);
        *(output++) = *(hrp++);
    }
    *(output++) = '1';
    for (i = 0; i < data_len; ++i) {
        if (*data >> 5) return 0;
        chk = bech32_polymod_step(chk) ^ (*data);
        *(output++) = charset[*(data++)];
    }
    for (i = 0; i < 6; ++i) {
        chk = bech32_polymod_step(chk);
    }
    chk ^= 1;
    for (i = 0; i < 6; ++i) {
        *(output++) = charset[(chk >> ((5 - i) * 5)) & 0x1f];
    }
    *output = 0;
    return 1;
}

variable_types:
hrp
char *

variable_types:
data
unsigned char *

variable_types:
chk
unsigned int

variable_types:
i
unsigned long

variable_types: ch int


original_code:
int bech32_decode(char* hrp, uint8_t *data, size_t *data_len, const char *input) {
    uint32_t chk = 1;
    size_t i;
    size_t input_len = strlen(input);
    size_t hrp_len;
    int have_lower = 0, have_upper = 0;
    if (input_len < 8 || input_len > 90) {
        return 0;
    }
    *data_len = 0;
    while (*data_len < input_len && input[(input_len - 1) - *data_len] != '1') {
        ++(*data_len);
    }
    hrp_len = input_len - (1 + *data_len);
    if (1 + *data_len >= input_len || *data_len < 6) {
        return 0;
    }
    *(data_len) -= 6;
    for (i = 0; i < hrp_len; ++i) {
        int ch = input[i];
        if (ch < 33 || ch > 126) {
            return 0;
        }
        if (ch >= 'a' && ch <= 'z') {
            have_lower = 1;
        } else if (ch >= 'A' && ch <= 'Z') {
            have_upper = 1;
            ch = (ch - 'A') + 'a';
        }
        hrp[i] = ch;
        chk = bech32_polymod_step(chk) ^ (ch >> 5);
    }
    hrp[i] = 0;
    chk = bech32_polymod_step(chk);
    for (i = 0; i < hrp_len; ++i) {
        chk = bech32_polymod_step(chk) ^ (input[i] & 0x1f);
    }
    ++i;
    while (i < input_len) {
        int v = (input[i] & 0x80) ? -1 : charset_rev[(int)input[i]];
        if (input[i] >= 'a' && input[i] <= 'z') have_lower = 1;
        if (input[i] >= 'A' && input[i] <= 'Z') have_upper = 1;
        if (v == -1) {
            return 0;
        }
        chk = bech32_polymod_step(chk) ^ v;
        if (i + 6 < input_len) {
            data[i - (1 + hrp_len)] = v;
        }
        ++i;
    }
    if (have_lower && have_upper) {
        return 0;
    }
    return chk == 1;
}

canonical_original_code:
int bech32_decode(char *hrp, unsigned char *data, unsigned long *data_len, char *input) {
    unsigned int chk = 1;
    unsigned long i;
    unsigned long input_len = strlen(input);
    unsigned long hrp_len;
    int have_lower = 0; int have_upper = 0;
    if (input_len < 8 || input_len > 90) {
        return 0;
    }
    *data_len = 0;
    while (*data_len < input_len && input[(input_len - 1) - *data_len] != '1') {
        ++(*data_len);
    }
    hrp_len = input_len - (1 + *data_len);
    if (1 + *data_len >= input_len || *data_len < 6) {
        return 0;
    }
    *(data_len) -= 6;
    for (i = 0; i < hrp_len; ++i) {
        int ch = input[i];
        if (ch < 33 || ch > 126) {
            return 0;
        }
        if (ch >= 'a' && ch <= 'z') {
            have_lower = 1;
        } else if (ch >= 'A' && ch <= 'Z') {
            have_upper = 1;
            ch = (ch - 'A') + 'a';
        }
        hrp[i] = ch;
        chk = bech32_polymod_step(chk) ^ (ch >> 5);
    }
    hrp[i] = 0;
    chk = bech32_polymod_step(chk);
    for (i = 0; i < hrp_len; ++i) {
        chk = bech32_polymod_step(chk) ^ (input[i] & 0x1f);
    }
    ++i;
    while (i < input_len) {
        int v = (input[i] & 0x80) ? -1 : charset_rev[(int)input[i]];
        if (input[i] >= 'a' && input[i] <= 'z') have_lower = 1;
        if (input[i] >= 'A' && input[i] <= 'Z') have_upper = 1;
        if (v == -1) {
            return 0;
        }
        chk = bech32_polymod_step(chk) ^ v;
        if (i + 6 < input_len) {
            data[i - (1 + hrp_len)] = v;
        }
        ++i;
    }
    if (have_lower && have_upper) {
        return 0;
    }
    return chk == 1;
}

variable_types:
input
char *

variable_types: v int


decompiled_code:
__int64 __fastcall segwit_addr_encode(_BYTE *a1, char *a2, int a3, unsigned __int8 *a4, __int64 a5)
{
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-68h] BYREF
unsigned __int8 v7; // [rsp+10h] [rbp-60h] BYREF
char v8[95]; // [rsp+11h] [rbp-5Fh] BYREF

v6 = 0LL;
result = 0LL;
if ( a3 <= 16 )
{
if ( a5 == 32 || a5 == 20 || (result = 0LL, a3) )
{
result = 0LL;
if ( (unsigned __int64)(a5 - 2) <= 0x26 )
{
v7 = a3;
convert_bits((__int64)v8, &v6, 5, a4, a5, 8, 1);
result = bech32_encode(a1, a2, &v7, v6 + 1);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, char *a2, int a3, unsigned __int8 *a4, __int64 a5)
{
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-68h] BYREF
unsigned __int8 v7; // [rsp+10h] [rbp-60h] BYREF
char v8[95]; // [rsp+11h] [rbp-5Fh] BYREF

v6 = 0LL;
result = 0LL;
if ( a3 <= 16 )
{
if ( a5 == 32 || a5 == 20 || (result = 0LL, a3) )
{
result = 0LL;
if ( (unsigned __int64)(a5 - 2) <= 0x26 )
{
v7 = a3;
func0((__int64)v8, &v6, 5, a4, a5, 8, 1);
result = func2(a1, a2, &v7, v6 + 1);
}
}
}
return result;
}

original_code:
int segwit_addr_encode(char *output, const char *hrp, int witver, const uint8_t *witprog, size_t witprog_len) {
    uint8_t data[65];
    size_t datalen = 0;
    if (witver > 16) return 0;
    if (witver == 0 && witprog_len != 20 && witprog_len != 32) return 0;
    if (witprog_len < 2 || witprog_len > 40) return 0;
    data[0] = witver;
    convert_bits(data + 1, &datalen, 5, witprog, witprog_len, 8, 1);
    ++datalen;
    return bech32_encode(output, hrp, data, datalen);
}

canonical_original_code:
int segwit_addr_encode(char *output, char *hrp, int witver, unsigned char *witprog, unsigned long witprog_len) {
    unsigned char data[65];
    unsigned long datalen = 0;
    if (witver > 16) return 0;
    if (witver == 0 && witprog_len != 20 && witprog_len != 32) return 0;
    if (witprog_len < 2 || witprog_len > 40) return 0;
    data[0] = witver;
    convert_bits(data + 1, &datalen, 5, witprog, witprog_len, 8, 1);
    ++datalen;
    return bech32_encode(output, hrp, data, datalen);
}

variable_types:
output
char *

variable_types: witver int

variable_types:
witprog
unsigned char *

variable_types:
data
unsigned char [65]

variable_types:
datalen
unsigned long


decompiled_code:
__int64 __fastcall segwit_addr_decode(_DWORD *a1, __int64 a2, _QWORD *a3, const char *a4, const char *a5)
{
unsigned int v7; // ebx
__int64 v8; // r15
__int64 v10; // [rsp+8h] [rbp-100h] BYREF
char s2[96]; // [rsp+10h] [rbp-F8h] BYREF
unsigned __int8 v12; // [rsp+70h] [rbp-98h] BYREF
unsigned __int8 v13[151]; // [rsp+71h] [rbp-97h] BYREF

v7 = bech32_decode(s2, (__int64)&v12, &v10, a5);
if ( v7 )
{
v8 = v10 - 1;
v7 = 0;
if ( (unsigned __int64)(v10 - 1) <= 0x40 )
{
v7 = strncmp(a4, s2, 0x54uLL);
if ( v7 )
{
v7 = 0;
}
else if ( v12 <= 0x10u )
{
*a3 = 0LL;
if ( (unsigned int)convert_bits(a2, a3, 8, v13, v8, 5, 0) )
{
if ( (unsigned __int64)(*a3 - 2LL) <= 0x26 && (*a3 == 32LL || *a3 == 20LL || v12) )
{
*a1 = v12;
v7 = 1;
}
}
else
{
v7 = 0;
}
}
}
}
return v7;
}

original_code:
int segwit_addr_decode(int* witver, uint8_t* witdata, size_t* witdata_len, const char* hrp, const char* addr) {
    uint8_t data[84];
    char hrp_actual[84];
    size_t data_len;
    if (!bech32_decode(hrp_actual, data, &data_len, addr)) return 0;
    if (data_len == 0 || data_len > 65) return 0;
    if (strncmp(hrp, hrp_actual, 84) != 0) return 0;
    if (data[0] > 16) return 0;
    *witdata_len = 0;
    if (!convert_bits(witdata, witdata_len, 8, data + 1, data_len - 1, 5, 0)) return 0;
    if (*witdata_len < 2 || *witdata_len > 40) return 0;
    if (data[0] == 0 && *witdata_len != 20 && *witdata_len != 32) return 0;
    *witver = data[0];
    return 1;
}

canonical_original_code:
int segwit_addr_decode(int *witver, unsigned char *witdata, unsigned long *witdata_len, char *hrp, char *addr) {
    unsigned char data[84];
    char hrp_actual[84];
    unsigned long data_len;
    if (!bech32_decode(hrp_actual, data, &data_len, addr)) return 0;
    if (data_len == 0 || data_len > 65) return 0;
    if (strncmp(hrp, hrp_actual, 84) != 0) return 0;
    if (data[0] > 16) return 0;
    *witdata_len = 0;
    if (!convert_bits(witdata, witdata_len, 8, data + 1, data_len - 1, 5, 0)) return 0;
    if (*witdata_len < 2 || *witdata_len > 40) return 0;
    if (data[0] == 0 && *witdata_len != 20 && *witdata_len != 32) return 0;
    *witver = data[0];
    return 1;
}

variable_types:
witver
int *

variable_types:
witdata
unsigned char *

variable_types:
addr
char *

variable_types:
data
unsigned char [84]


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

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

original_code:
BitcoinKeyPrefix BitcoinNetworkType_GetPublicKeyPrefix(const struct BitcoinNetworkType *n)
{
 return n->public_key_prefix;
}

canonical_original_code:
unsigned int BitcoinNetworkType_GetPublicKeyPrefix(struct BitcoinNetworkType *n)
{
 return n->public_key_prefix;
}

variable_types: struct BitcoinNetworkType { char *name; char *hrp; unsigned int public_key_prefix; } *


decompiled_code:
__int64 __fastcall BitcoinNetworkType_GetPrivateKeyPrefix(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
BitcoinKeyPrefix BitcoinNetworkType_GetPrivateKeyPrefix(const struct BitcoinNetworkType *n)
{
 return n->private_key_prefix;
}

canonical_original_code:
unsigned int BitcoinNetworkType_GetPrivateKeyPrefix(struct BitcoinNetworkType *n)
{
 return n->private_key_prefix;
}

user_defined_types: struct BitcoinNetworkType { char *name; char *hrp; unsigned int public_key_prefix; }


decompiled_code:
char **__fastcall Bitcoin_GetNetworkTypeByName(char *s1)
{
char **v1; // rbx

v1 = network_types;
while ( strcmp(s1, *v1) )
{
v1 += 4;
if ( v1 == (char **)&unk_4A0 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
char **__fastcall func2(char *s1)
{
char **v1; // rbx

v1 = network_types;
while ( strcmp(s1, *v1) )
{
v1 += 4;
if ( v1 == (char **)&unk_4A0 )
return 0LL;
}
return v1;
}

original_code:
const struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByName(const char *name)
{
 const struct BitcoinNetworkType *pn = network_types;
 while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
  if (strcmp(name, pn->name) == 0) {
   return pn;
  }
  pn++;
 }
 return ((void *)0);
}

canonical_original_code:
struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByName(char *name)
{
 struct BitcoinNetworkType *pn = network_types;
 while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
  if (strcmp(name, pn->name) == 0) {
   return pn;
  }
  pn++;
 }
 return ((void *)0);
}

variable_types:
name
char *

return_type: struct BitcoinNetworkType { char *name; char *hrp; unsigned int public_key_prefix; } *


decompiled_code:
char **__fastcall Bitcoin_GetNetworkTypeByHrp(char *s1)
{
char **v1; // rbx

v1 = network_types;
while ( strcmp(s1, v1[1]) )
{
v1 += 4;
if ( v1 == (char **)&unk_4A0 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
char **__fastcall func3(char *s1)
{
char **v1; // rbx

v1 = network_types;
while ( strcmp(s1, v1[1]) )
{
v1 += 4;
if ( v1 == (char **)&unk_4A0 )
return 0LL;
}
return v1;
}

original_code:
const struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByHrp(const char *hrp)
{
 const struct BitcoinNetworkType *pn = network_types;
 while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
  if (strcmp(hrp, pn->hrp) == 0) {
   return pn;
  }
  pn++;
 }
 return ((void *)0);
}

canonical_original_code:
struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByHrp(char *hrp)
{
 struct BitcoinNetworkType *pn = network_types;
 while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
  if (strcmp(hrp, pn->hrp) == 0) {
   return pn;
  }
  pn++;
 }
 return ((void *)0);
}

variable_types:
hrp
char *


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

result = network_types;
while ( *((_DWORD *)result + 6) != a1 )
{
result += 4;
if ( result == (char **)&unk_4A0 )
return 0LL;
}
return result;
}

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

result = network_types;
while ( *((_DWORD *)result + 6) != a1 )
{
result += 4;
if ( result == (char **)&unk_4A0 )
return 0LL;
}
return result;
}

original_code:
const struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByPrivateKeyPrefix(const BitcoinKeyPrefix prefix)
{
 const struct BitcoinNetworkType *pn = network_types;
 while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
  if (prefix == pn->private_key_prefix) {
   return pn;
  }
  pn++;
 }
 return ((void *)0);
}

canonical_original_code:
struct BitcoinNetworkType *Bitcoin_GetNetworkTypeByPrivateKeyPrefix(unsigned int prefix)
{
 struct BitcoinNetworkType *pn = network_types;
 while (pn != network_types + (sizeof(network_types)/sizeof(network_types[0]))) {
  if (prefix == pn->private_key_prefix) {
   return pn;
  }
  pn++;
 }
 return ((void *)0);
}

variable_types:
prefix
unsigned int


decompiled_code:
__int64 __fastcall Bitcoin_SHA256(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[136]; // [rsp+0h] [rbp-88h] BYREF

SHA256_Init(v5);
SHA256_Update(v5, a2, a3);
return SHA256_Final(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[136]; // [rsp+0h] [rbp-88h] BYREF

SHA256_Init(v5);
SHA256_Update(v5, a2, a3);
return SHA256_Final(a1, v5);
}

original_code:
void Bitcoin_SHA256(struct BitcoinSHA256 *output, const void *input, size_t size)
{
 SHA256_CTX ctx;
 SHA256_Init(&ctx);
 SHA256_Update(&ctx, input, size);
 SHA256_Final(output->data, &ctx);
}

canonical_original_code:
void Bitcoin_SHA256(struct BitcoinSHA256 *output, void *input, unsigned long size)
{
 struct SHA256state_st ctx;
 SHA256_Init(&ctx);
 SHA256_Update(&ctx, input, size);
 SHA256_Final(output->data, &ctx);
}

variable_types: struct BitcoinSHA256 { unsigned char data[-1]; } *

variable_types:
input
void *

variable_types:
size
unsigned long

variable_types: struct SHA256state_st { unsigned int h[8]; unsigned int Nl; unsigned int data[16]; unsigned int num; }


decompiled_code:
__int64 __fastcall Bitcoin_DoubleSHA256(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[112]; // [rsp+0h] [rbp-A8h] BYREF
char v6[56]; // [rsp+70h] [rbp-38h] BYREF

SHA256_Init(v5);
SHA256_Update(v5, a2, a3);
SHA256_Final(v6, v5);
SHA256_Init(v5);
SHA256_Update(v5, v6, 32LL);
return SHA256_Final(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[112]; // [rsp+0h] [rbp-A8h] BYREF
char v6[56]; // [rsp+70h] [rbp-38h] BYREF

SHA256_Init(v5);
SHA256_Update(v5, a2, a3);
SHA256_Final(v6, v5);
SHA256_Init(v5);
SHA256_Update(v5, v6, 32LL);
return SHA256_Final(a1, v5);
}

original_code:
void Bitcoin_DoubleSHA256(struct BitcoinSHA256 *output, const void *input, size_t size)
{
 struct BitcoinSHA256 round1;
 SHA256_CTX ctx;
 SHA256_Init(&ctx);
 SHA256_Update(&ctx, input, size);
 SHA256_Final(round1.data, &ctx);
 SHA256_Init(&ctx);
 SHA256_Update(&ctx, &round1.data, (32));
 SHA256_Final(output->data, &ctx);
}

canonical_original_code:
void Bitcoin_DoubleSHA256(struct BitcoinSHA256 *output, void *input, unsigned long size)
{
 struct BitcoinSHA256 round1;
 struct SHA256state_st ctx;
 SHA256_Init(&ctx);
 SHA256_Update(&ctx, input, size);
 SHA256_Final(round1.data, &ctx);
 SHA256_Init(&ctx);
 SHA256_Update(&ctx, &round1.data, (32));
 SHA256_Final(output->data, &ctx);
}

variable_types: struct BitcoinSHA256 { unsigned char data[-1]; }

user_defined_types: struct SHA256state_st { unsigned int h[8]; unsigned int Nl; unsigned int data[16]; unsigned int num; }


decompiled_code:
__int64 __fastcall Bitcoin_RIPEMD160(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[120]; // [rsp+0h] [rbp-78h] BYREF

RIPEMD160_Init(v5);
RIPEMD160_Update(v5, a2, a3);
return RIPEMD160_Final(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[120]; // [rsp+0h] [rbp-78h] BYREF

RIPEMD160_Init(v5);
RIPEMD160_Update(v5, a2, a3);
return RIPEMD160_Final(a1, v5);
}

original_code:
void Bitcoin_RIPEMD160(struct BitcoinRIPEMD160 *output, const void *input, size_t size)
{
 RIPEMD160_CTX ctx;
 RIPEMD160_Init(&ctx);
 RIPEMD160_Update(&ctx, input, size);
 RIPEMD160_Final(output->data, &ctx);
}

canonical_original_code:
void Bitcoin_RIPEMD160(struct BitcoinRIPEMD160 *output, void *input, unsigned long size)
{
 struct RIPEMD160state_st ctx;
 RIPEMD160_Init(&ctx);
 RIPEMD160_Update(&ctx, input, size);
 RIPEMD160_Final(output->data, &ctx);
}

variable_types: struct BitcoinRIPEMD160 { unsigned char data[-1]; } *

variable_types: struct RIPEMD160state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; }


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

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
result = malloc(4LL * a3);
*(_QWORD *)(a1 + 8) = result;
if ( a3 > 0 )
{
result = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * (_QWORD)result) = (_DWORD)result;
result = (char *)result + 1;
}
while ( result != (void *)(unsigned int)a3 );
}
return result;
}

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

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = a3;
result = malloc(4LL * a3);
*(_QWORD *)(a1 + 8) = result;
if ( a3 > 0 )
{
result = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * (_QWORD)result) = (_DWORD)result;
result = (char *)result + 1;
}
while ( result != (void *)(unsigned int)a3 );
}
return result;
}

original_code:
void Combination_create(struct Combination *c, int n, int r)
{
 int i;
 c->n = n;
 c->r = r;
 c->k = malloc(sizeof(*c->k) * r);
 for (i=0; i < r; i++) {
  c->k[i] = i;
 }
}

variable_types: struct Combination { int n; int r; int *k; } *

variable_types: n int

variable_types: r int

variable_types: i int


decompiled_code:
void __fastcall Combination_destroy(__int64 a1)
{
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free(*(void **)(a1 + 8));
}

original_code:
void Combination_destroy(struct Combination *c)
{
 free(c->k);
}

user_defined_types: struct Combination { int n; int r; int *k; }


original_code:
int Combination_next(struct Combination *c)
{
 int i, j;
 for (i=c->r-1; i >= 0; i--) {
  c->k[i]++;
  for (j=i+1; j<c->r; j++) c->k[j] = c->k[j-1]+1;
  if (c->k[c->r-1] != c->n) break;
  if (!i) return 0;
 }
 return 1;
}

canonical_original_code:
int Combination_next(struct Combination *c)
{
 int i; int j;
 for (i=c->r-1; i >= 0; i--) {
  c->k[i]++;
  for (j=i+1; j<c->r; j++) c->k[j] = c->k[j-1]+1;
  if (c->k[c->r-1] != c->n) break;
  if (!i) return 0;
 }
 return 1;
}

variable_types: j int


decompiled_code:
__int64 __fastcall Bitcoin_EncodeBase58Check(__int64 a1, unsigned __int64 a2, _QWORD *a3, const void *a4, size_t a5)
{
size_t v7; // rbp
__int64 v8; // r15
char *v9; // rbx
int v11[22]; // [rsp+10h] [rbp-58h] BYREF

v7 = a5;
v8 = a5 + 4;
v9 = (char *)malloc(a5 + 4);
Bitcoin_DoubleSHA256(v11, a4, v7);
memcpy(v9, a4, v7);
*(_DWORD *)&v9[v7] = v11[0];
LODWORD(v7) = Bitcoin_EncodeBase58(a1, a2, a3, v9, v8);
free(v9);
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2, _QWORD *a3, const void *a4, size_t a5)
{
size_t v7; // rbp
__int64 v8; // r15
char *v9; // rbx
int v11[22]; // [rsp+10h] [rbp-58h] BYREF

v7 = a5;
v8 = a5 + 4;
v9 = (char *)malloc(a5 + 4);
Bitcoin_DoubleSHA256(v11, a4, v7);
memcpy(v9, a4, v7);
*(_DWORD *)&v9[v7] = v11[0];
LODWORD(v7) = func0(a1, a2, a3, v9, v8);
free(v9);
return (unsigned int)v7;
}

original_code:
BitcoinResult Bitcoin_EncodeBase58Check(
 char *output, size_t output_size, size_t *encoded_output_size,
 const void *source, size_t source_size
)
{
 struct BitcoinSHA256 checksum;
 size_t buffer_size = source_size + 4;
 unsigned char *buffer = malloc(buffer_size);
 BitcoinResult result = 0;
 Bitcoin_DoubleSHA256(&checksum, source, source_size);
 memcpy(buffer, source, source_size);
 memcpy(buffer + source_size, &checksum, 4);
 result = Bitcoin_EncodeBase58(output, output_size, encoded_output_size, buffer, buffer_size);
 free(buffer);
 return result;
}

canonical_original_code:
enum BitcoinResult Bitcoin_EncodeBase58Check(char *output, unsigned long output_size, unsigned long *encoded_output_size, void *source, unsigned long source_size)
{
 struct BitcoinSHA256 checksum;
 unsigned long buffer_size = source_size + 4;
 unsigned char *buffer = malloc(buffer_size);
 enum BitcoinResult result = 0;
 Bitcoin_DoubleSHA256(&checksum, source, source_size);
 memcpy(buffer, source, source_size);
 memcpy(buffer + source_size, &checksum, 4);
 result = Bitcoin_EncodeBase58(output, output_size, encoded_output_size, buffer, buffer_size);
 free(buffer);
 return result;
}

variable_types:
output
char *

variable_types:
source
void *

variable_types:
buffer
unsigned char *

variable_types: enum BitcoinResult { BITCOIN_SUCCESS=0, BITCOIN_ERROR=1, BITCOIN_ERROR_NOT_IMPLEMENTED=2, BITCOIN_ERROR_PRIVATE_KEY_INVALID_FORMAT=3, BITCOIN_ERROR_PUBLIC_KEY_INVALID_FORMAT=4, BITCOIN_ERROR_OUTPUT_BUFFER_TOO_SMALL=5, BITCOIN_ERROR_CHECKSUM_FAILURE=6, BITCOIN_ERROR_INVALID_FORMAT=7, BITCOIN_ERROR_IMPOSSIBLE_CONVERSION=8, BITCOIN_ERROR_FILE=9, BITCOIN_ERROR_LIBRARY_FAILURE=10, BITCOIN_ERROR_END_OF_FILE=11 }

user_defined_types: struct BitcoinSHA256 { unsigned char data[-1]; }


decompiled_code:
__int64 __fastcall Bitcoin_DecodeBase58Check(char *a1, size_t a2, _QWORD *a3, char *a4, __int64 a5)
{
unsigned int v6; // ebp
__int64 v8; // r13
__int64 v9; // [rsp+8h] [rbp-50h] BYREF
char s1[72]; // [rsp+10h] [rbp-48h] BYREF

v6 = Bitcoin_DecodeBase58(a1, a2, &v9, a4, a5);
if ( !v6 )
{
Bitcoin_DoubleSHA256(s1, a1, v9 - 4);
v8 = v9 - 4;
if ( !memcmp(s1, &a1[v9 - 4], 4uLL) )
*a3 = v8;
else
v6 = 6;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, size_t a2, _QWORD *a3, char *a4, __int64 a5)
{
unsigned int v6; // ebp
__int64 v8; // r13
__int64 v9; // [rsp+8h] [rbp-50h] BYREF
char s1[72]; // [rsp+10h] [rbp-48h] BYREF

v6 = func2(a1, a2, &v9, a4, a5);
if ( !v6 )
{
Bitcoin_DoubleSHA256(s1, a1, v9 - 4);
v8 = v9 - 4;
if ( !memcmp(s1, &a1[v9 - 4], 4uLL) )
*a3 = v8;
else
v6 = 6;
}
return v6;
}

original_code:
BitcoinResult Bitcoin_DecodeBase58Check(
 uint8_t *output, size_t output_buffer_size, size_t *decoded_output_size,
 const void *input, size_t input_size
)
{
 struct BitcoinSHA256 hash;
 size_t temp_decoded_output_size;
 BitcoinResult result = Bitcoin_DecodeBase58(
  output, output_buffer_size, &temp_decoded_output_size,
  input, input_size
 );
 if (result != BITCOIN_SUCCESS) {
  return result;
 }
 Bitcoin_DoubleSHA256(&hash, output,
  temp_decoded_output_size - 4
 );
 if (memcmp(hash.data
  ,output + temp_decoded_output_size - 4
  ,4)
 ) {
  return BITCOIN_ERROR_CHECKSUM_FAILURE;
 }
 *decoded_output_size = temp_decoded_output_size -
  4;
 return BITCOIN_SUCCESS;
}

canonical_original_code:
enum BitcoinResult Bitcoin_DecodeBase58Check(unsigned char *output, unsigned long output_buffer_size, unsigned long *decoded_output_size, void *input, unsigned long input_size)
{
 struct BitcoinSHA256 hash;
 unsigned long temp_decoded_output_size;
 enum BitcoinResult result = Bitcoin_DecodeBase58(
  output, output_buffer_size, &temp_decoded_output_size,
  input, input_size
 );
 if (result != BITCOIN_SUCCESS) {
  return result;
 }
 Bitcoin_DoubleSHA256(&hash, output,
  temp_decoded_output_size - 4
 );
 if (memcmp(hash.data
  ,output + temp_decoded_output_size - 4
  ,4)
 ) {
  return BITCOIN_ERROR_CHECKSUM_FAILURE;
 }
 *decoded_output_size = temp_decoded_output_size -
  4;
 return BITCOIN_SUCCESS;
}

variable_types:
output
unsigned char *