decompiled_code:
__int64 __fastcall f1f2_to_s(_BYTE *a1, const char *a2, const char *a3, const char *a4, char *a5)
{
int v8; // er15
__int64 v9; // rdx
__int64 v10; // rax
__int64 v11; // rbp
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rdx
__int64 v15; // rax
__int64 v17; // rdx
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r9
__int64 v21; // [rsp+8h] [rbp-5C0h]
int v22; // [rsp+10h] [rbp-5B8h] BYREF
int v23; // [rsp+14h] [rbp-5B4h] BYREF
unsigned int v24; // [rsp+18h] [rbp-5B0h] BYREF
int v25; // [rsp+1Ch] [rbp-5ACh] BYREF
int v26; // [rsp+20h] [rbp-5A8h] BYREF
int v27; // [rsp+24h] [rbp-5A4h] BYREF
void *addr; // [rsp+28h] [rbp-5A0h] BYREF
size_t len; // [rsp+30h] [rbp-598h] BYREF
void *v30; // [rsp+38h] [rbp-590h] BYREF
size_t v31; // [rsp+40h] [rbp-588h] BYREF
__int64 v32; // [rsp+48h] [rbp-580h] BYREF
__int64 v33; // [rsp+50h] [rbp-578h] BYREF
__int64 v34; // [rsp+58h] [rbp-570h] BYREF
_QWORD v35[16]; // [rsp+60h] [rbp-568h] BYREF
_QWORD v36[16]; // [rsp+E0h] [rbp-4E8h] BYREF
__int64 v37[22]; // [rsp+160h] [rbp-468h] BYREF
__int64 v38; // [rsp+210h] [rbp-3B8h] BYREF
__int64 v39; // [rsp+228h] [rbp-3A0h]
__int64 v40; // [rsp+2F0h] [rbp-2D8h] BYREF
__int64 v41; // [rsp+308h] [rbp-2C0h]
char v42[224]; // [rsp+3D0h] [rbp-1F8h] BYREF
char v43[280]; // [rsp+4B0h] [rbp-118h] BYREF

addr = 0LL;
len = 0LL;
v30 = 0LL;
v31 = 0LL;
if ( !a1 || !*a1 )
{
v9 = 53LL;
goto LABEL_34;
}
if ( !a2 || !*a2 )
{
v9 = 54LL;
goto LABEL_34;
}
if ( !a3 || !*a3 )
{
v9 = 55LL;
goto LABEL_34;
}
if ( !a4 || !*a4 )
{
v9 = 56LL;
goto LABEL_34;
}
if ( !strcmp(a2, a3) )
{
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", 57LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = is_tbl(a1, &v22, v37);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 59LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v9 = 60LL;
if ( v22 < 0 )
goto LABEL_34;
v21 = v37[0];
v8 = is_fld(a1, 0xFFFFFFFFLL, a2, &v23, &v38, &v25, v42);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 64LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v9 = 65LL;
if ( v23 < 0 )
{
LABEL_34:
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", v9, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = get_data(&addr, &len, 0LL, "./dir_wr_verbs/f1f2_to_s.c");
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 66LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = is_fld(a1, 0xFFFFFFFFLL, a3, &v24, &v40, &v26, v43);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 69LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
if ( (v24 & 0x80000000) != 0 )
{
v9 = 70LL;
goto LABEL_34;
}
v8 = get_data(&v30, &v31, 0LL, v24);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 71LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = partition(v21, 1LL, 16LL, &v32, &v27);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 74LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
if ( strcmp(a4, "sum") )
goto LABEL_35;
memset(v35, 0, sizeof(v35));
memset(v36, 0, sizeof(v36));
if ( (_DWORD)v39 != 2 )
{
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", 78LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
if ( v25 >= 0 )
{
v9 = 79LL;
goto LABEL_34;
}
if ( v26 >= 0 )
{
v9 = 80LL;
goto LABEL_34;
}
LODWORD(v10) = v27;
v11 = 0LL;
if ( v27 <= 0 )
goto LABEL_70;
while ( 1 )
{
v12 = v32;
v33 = 0LL;
v34 = 0LL;
v13 = v32 * v11;
if ( (_DWORD)v10 - 1 == (_DWORD)v11 )
v12 = v21 - v32 * v11;
if ( (_DWORD)v41 == 4 )
{
nn_f_to_s_sum_I4((char *)v30 + 4 * v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
else if ( (unsigned int)v41 > 4 )
{
if ( (_DWORD)v41 != 5 )
{
LABEL_59:
v35[v11] = 0LL;
v36[v11] = 0LL;
v9 = 113LL;
goto LABEL_34;
}
nn_f_to_s_sum_I8((char *)v30 + 8 * v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
else if ( (_DWORD)v41 == 2 )
{
nn_f_to_s_sum_I1((char *)v30 + v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
else
{
if ( (_DWORD)v41 != 3 )
goto LABEL_59;
nn_f_to_s_sum_I2((char *)v30 + 2 * v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
v36[v11] = v15;
v10 = v27;
v35[v11] = v14;
if ( (int)v10 <= (int)v11 + 1 )
break;
++v11;
}
if ( (int)v10 <= 0 )
{
LABEL_70:
v19 = 0LL;
v20 = 0LL;
}
else
{
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
do
{
v20 += v35[v18];
v19 += v36[v18++];
}
while ( v10 != v18 );
}
sprintf(a5, "%lld:%lld:%lld\n", v20, v19, v21);
LABEL_35:
if ( addr )
{
if ( len )
{
munmap(addr, len);
addr = 0LL;
len = 0LL;
goto LABEL_38;
}
LABEL_44:
v17 = 122LL;
LABEL_45:
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", v17, "./dir_wr_verbs/f1f2_to_s.c");
return (unsigned int)v8;
}
if ( len )
goto LABEL_44;
LABEL_38:
if ( !v30 )
{
if ( !v31 )
return (unsigned int)v8;
goto LABEL_47;
}
if ( !v31 )
{
LABEL_47:
v17 = 123LL;
goto LABEL_45;
}
munmap(v30, v31);
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, const char *a2, const char *a3, const char *a4, char *a5)
{
int v8; // er15
__int64 v9; // rdx
__int64 v10; // rax
__int64 v11; // rbp
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rdx
__int64 v15; // rax
__int64 v17; // rdx
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r9
__int64 v21; // [rsp+8h] [rbp-5C0h]
int v22; // [rsp+10h] [rbp-5B8h] BYREF
int v23; // [rsp+14h] [rbp-5B4h] BYREF
unsigned int v24; // [rsp+18h] [rbp-5B0h] BYREF
int v25; // [rsp+1Ch] [rbp-5ACh] BYREF
int v26; // [rsp+20h] [rbp-5A8h] BYREF
int v27; // [rsp+24h] [rbp-5A4h] BYREF
void *addr; // [rsp+28h] [rbp-5A0h] BYREF
size_t len; // [rsp+30h] [rbp-598h] BYREF
void *v30; // [rsp+38h] [rbp-590h] BYREF
size_t v31; // [rsp+40h] [rbp-588h] BYREF
__int64 v32; // [rsp+48h] [rbp-580h] BYREF
__int64 v33; // [rsp+50h] [rbp-578h] BYREF
__int64 v34; // [rsp+58h] [rbp-570h] BYREF
_QWORD v35[16]; // [rsp+60h] [rbp-568h] BYREF
_QWORD v36[16]; // [rsp+E0h] [rbp-4E8h] BYREF
__int64 v37[22]; // [rsp+160h] [rbp-468h] BYREF
__int64 v38; // [rsp+210h] [rbp-3B8h] BYREF
__int64 v39; // [rsp+228h] [rbp-3A0h]
__int64 v40; // [rsp+2F0h] [rbp-2D8h] BYREF
__int64 v41; // [rsp+308h] [rbp-2C0h]
char v42[224]; // [rsp+3D0h] [rbp-1F8h] BYREF
char v43[280]; // [rsp+4B0h] [rbp-118h] BYREF

addr = 0LL;
len = 0LL;
v30 = 0LL;
v31 = 0LL;
if ( !a1 || !*a1 )
{
v9 = 53LL;
goto LABEL_34;
}
if ( !a2 || !*a2 )
{
v9 = 54LL;
goto LABEL_34;
}
if ( !a3 || !*a3 )
{
v9 = 55LL;
goto LABEL_34;
}
if ( !a4 || !*a4 )
{
v9 = 56LL;
goto LABEL_34;
}
if ( !strcmp(a2, a3) )
{
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", 57LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = is_tbl(a1, &v22, v37);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 59LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v9 = 60LL;
if ( v22 < 0 )
goto LABEL_34;
v21 = v37[0];
v8 = is_fld(a1, 0xFFFFFFFFLL, a2, &v23, &v38, &v25, v42);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 64LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v9 = 65LL;
if ( v23 < 0 )
{
LABEL_34:
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", v9, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = get_data(&addr, &len, 0LL, "./dir_wr_verbs/f1f2_to_s.c");
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 66LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = is_fld(a1, 0xFFFFFFFFLL, a3, &v24, &v40, &v26, v43);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 69LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
if ( (v24 & 0x80000000) != 0 )
{
v9 = 70LL;
goto LABEL_34;
}
v8 = get_data(&v30, &v31, 0LL, v24);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 71LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
v8 = partition(v21, 1LL, 16LL, &v32, &v27);
if ( v8 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 74LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
if ( strcmp(a4, "sum") )
goto LABEL_35;
memset(v35, 0, sizeof(v35));
memset(v36, 0, sizeof(v36));
if ( (_DWORD)v39 != 2 )
{
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", 78LL, "./dir_wr_verbs/f1f2_to_s.c");
goto LABEL_35;
}
if ( v25 >= 0 )
{
v9 = 79LL;
goto LABEL_34;
}
if ( v26 >= 0 )
{
v9 = 80LL;
goto LABEL_34;
}
LODWORD(v10) = v27;
v11 = 0LL;
if ( v27 <= 0 )
goto LABEL_70;
while ( 1 )
{
v12 = v32;
v33 = 0LL;
v34 = 0LL;
v13 = v32 * v11;
if ( (_DWORD)v10 - 1 == (_DWORD)v11 )
v12 = v21 - v32 * v11;
if ( (_DWORD)v41 == 4 )
{
nn_f_to_s_sum_I4((char *)v30 + 4 * v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
else if ( (unsigned int)v41 > 4 )
{
if ( (_DWORD)v41 != 5 )
{
LABEL_59:
v35[v11] = 0LL;
v36[v11] = 0LL;
v9 = 113LL;
goto LABEL_34;
}
nn_f_to_s_sum_I8((char *)v30 + 8 * v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
else if ( (_DWORD)v41 == 2 )
{
nn_f_to_s_sum_I1((char *)v30 + v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
else
{
if ( (_DWORD)v41 != 3 )
goto LABEL_59;
nn_f_to_s_sum_I2((char *)v30 + 2 * v13, (char *)addr + v13, v12, &v34, &v33);
v14 = v33;
v15 = v34;
}
v36[v11] = v15;
v10 = v27;
v35[v11] = v14;
if ( (int)v10 <= (int)v11 + 1 )
break;
++v11;
}
if ( (int)v10 <= 0 )
{
LABEL_70:
v19 = 0LL;
v20 = 0LL;
}
else
{
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
do
{
v20 += v35[v18];
v19 += v36[v18++];
}
while ( v10 != v18 );
}
sprintf(a5, "%lld:%lld:%lld\n", v20, v19, v21);
LABEL_35:
if ( addr )
{
if ( len )
{
munmap(addr, len);
addr = 0LL;
len = 0LL;
goto LABEL_38;
}
LABEL_44:
v17 = 122LL;
LABEL_45:
v8 = -1;
fprintf(stderr, "Line %3d of File %s \n", v17, "./dir_wr_verbs/f1f2_to_s.c");
return (unsigned int)v8;
}
if ( len )
goto LABEL_44;
LABEL_38:
if ( !v30 )
{
if ( !v31 )
return (unsigned int)v8;
goto LABEL_47;
}
if ( !v31 )
{
LABEL_47:
v17 = 123LL;
goto LABEL_45;
}
munmap(v30, v31);
return (unsigned int)v8;
}

original_code:
int
f1f2_to_s(
   const char *tbl,
   const char *f1,
   const char *f2,
   const char *op,
   char *rslt_buf,
   int sz_rslt_buf
   )
{
  int status = 0;
  char *f1_X = ((void *)0); size_t f1_nX = 0;
  char *f2_X = ((void *)0); size_t f2_nX = 0;
  long long nR;
  TBL_REC_TYPE tbl_rec; int tbl_id;
  FLD_REC_TYPE f1_rec; int f1_id;
  FLD_REC_TYPE f2_rec; int f2_id;
  FLD_REC_TYPE nn_f1_rec; int nn_f1_id;
  FLD_REC_TYPE nn_f2_rec; int nn_f2_id;
  long long rslt[16], cnt[16];
  if ( ( tbl == ((void *)0) ) || ( *tbl == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 53, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( ( f1 == ((void *)0) ) || ( *f1 == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 54, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( ( f2 == ((void *)0) ) || ( *f2 == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 55, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( ( op == ((void *)0) ) || ( *op == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 56, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( strcmp(f1, f2) == 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 57, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  status = is_tbl(tbl, &tbl_id, &tbl_rec); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 59, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( tbl_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 60, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  nR = tbl_rec.nR;
  status = is_fld(tbl, -1, f1, &f1_id, &f1_rec, &nn_f1_id, &nn_f1_rec);
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 64, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( f1_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 65, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  status = get_data(f1_rec, &f1_X, &f1_nX, 0); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 66, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  status = is_fld(tbl, -1, f2, &f2_id, &f2_rec, &nn_f2_id, &nn_f2_rec);
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 69, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( f2_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 70, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  status = get_data(f2_rec, &f2_X, &f2_nX, 0); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 71, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  long long block_size; int nT;
  status = partition(nR, 1, 16, &block_size, &nT); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 74, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( strcmp(op, "sum") == 0 ) {
    for ( int tid = 0; tid < 16; tid++ ) { rslt[tid] = 0; }
    for ( int tid = 0; tid < 16; tid++ ) { cnt[tid] = 0; }
    if ( f1_rec.fldtype != I1 ) { { { fprintf(stderr, "Line %3d of File %s \n", 78, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
    if ( nn_f1_id >= 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 79, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
    if ( nn_f2_id >= 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 80, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
    for ( int tid = 0; tid < nT; tid++ ) {
      if ( status < 0 ) { continue; }
      long long lb = tid * block_size;
      long long ub = lb + block_size;
      if ( tid == (nT-1) ) { ub = nR; }
      long long tnR = ub - lb;
      char *f2I1 = (char *) f2_X; f2I1 += lb;
      short *f2I2 = (short *) f2_X; f2I2 += lb;
      int *f2I4 = (int *) f2_X; f2I4 += lb;
      long long *f2I8 = (long long *)f2_X; f2I8 += lb;
      long long trsltI8 = 0, tcntI8 = 0;
      switch ( f2_rec.fldtype ) {
      case I1 :
 nn_f_to_s_sum_I1(f2I1, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      case I2 :
 nn_f_to_s_sum_I2(f2I2, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      case I4 :
 nn_f_to_s_sum_I4(f2I4, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      case I8 :
 nn_f_to_s_sum_I8(f2I8, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      default :
 status = -1;
 break;
      }
      rslt[tid] = trsltI8;
      cnt[tid] = tcntI8;
    }
    { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 113, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
    long long final_rslt = 0, final_cnt = 0;
    for ( int tid = 0; tid < nT; tid++ ) {
      final_rslt += rslt[tid];
      final_cnt += cnt[tid];
    }
    sprintf(rslt_buf, "%lld:%lld:%lld\n", final_rslt, final_cnt, nR);
  }
 BYE:
  { if ( ( f1_X == ((void *)0) ) && ( f1_nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 122, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( ( f1_X != ((void *)0) ) && ( f1_nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 122, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( f1_X != ((void *)0) ) { munmap(f1_X, f1_nX); f1_X = ((void *)0); f1_nX = 0; } };
  { if ( ( f2_X == ((void *)0) ) && ( f2_nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 123, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( ( f2_X != ((void *)0) ) && ( f2_nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 123, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( f2_X != ((void *)0) ) { munmap(f2_X, f2_nX); f2_X = ((void *)0); f2_nX = 0; } };
  return(status);
}

canonical_original_code:
int f1f2_to_s(char *tbl, char *f1, char *f2, char *op, char *rslt_buf, int sz_rslt_buf)
{
  int status = 0;
  char *f1_X = ((void *)0); unsigned long f1_nX = 0;
  char *f2_X = ((void *)0); unsigned long f2_nX = 0;
  long long nR;
  struct _TBL_REC_TYPE tbl_rec; int tbl_id;
  struct _FLD_REC_TYPE f1_rec; int f1_id;
  struct _FLD_REC_TYPE f2_rec; int f2_id;
  struct _FLD_REC_TYPE nn_f1_rec; int nn_f1_id;
  struct _FLD_REC_TYPE nn_f2_rec; int nn_f2_id;
  long long rslt[16]; long long cnt[16];
  if ( ( tbl == ((void *)0) ) || ( *tbl == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 53, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( ( f1 == ((void *)0) ) || ( *f1 == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 54, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( ( f2 == ((void *)0) ) || ( *f2 == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 55, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( ( op == ((void *)0) ) || ( *op == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 56, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  if ( strcmp(f1, f2) == 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 57, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  status = is_tbl(tbl, &tbl_id, &tbl_rec); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 59, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( tbl_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 60, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  nR = tbl_rec.nR;
  status = is_fld(tbl, -1, f1, &f1_id, &f1_rec, &nn_f1_id, &nn_f1_rec);
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 64, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( f1_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 65, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  status = get_data(f1_rec, &f1_X, &f1_nX, 0); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 66, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  status = is_fld(tbl, -1, f2, &f2_id, &f2_rec, &nn_f2_id, &nn_f2_rec);
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 69, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( f2_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 70, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
  status = get_data(f2_rec, &f2_X, &f2_nX, 0); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 71, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  long long block_size; int nT;
  status = partition(nR, 1, 16, &block_size, &nT); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 74, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
  if ( strcmp(op, "sum") == 0 ) {
    for ( int tid = 0; tid < 16; tid++ ) { rslt[tid] = 0; }
    for ( int tid = 0; tid < 16; tid++ ) { cnt[tid] = 0; }
    if ( f1_rec.fldtype != I1 ) { { { fprintf(stderr, "Line %3d of File %s \n", 78, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
    if ( nn_f1_id >= 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 79, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
    if ( nn_f2_id >= 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 80, "./dir_wr_verbs/f1f2_to_s.c"); }; status = -1 ; goto BYE; }; }
    for ( int tid = 0; tid < nT; tid++ ) {
      if ( status < 0 ) { continue; }
      long long lb = tid * block_size;
      long long ub = lb + block_size;
      if ( tid == (nT-1) ) { ub = nR; }
      long long tnR = ub - lb;
      char *f2I1 = (char *) f2_X; f2I1 += lb;
      short *f2I2 = (short *) f2_X; f2I2 += lb;
      int *f2I4 = (int *) f2_X; f2I4 += lb;
      long long *f2I8 = (long long *)f2_X; f2I8 += lb;
      long long trsltI8 = 0; long long tcntI8 = 0;
      switch ( f2_rec.fldtype ) {
      case I1 :
 nn_f_to_s_sum_I1(f2I1, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      case I2 :
 nn_f_to_s_sum_I2(f2I2, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      case I4 :
 nn_f_to_s_sum_I4(f2I4, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      case I8 :
 nn_f_to_s_sum_I8(f2I8, f1_X+lb, tnR, &tcntI8, &trsltI8);
 break;
      default :
 status = -1;
 break;
      }
      rslt[tid] = trsltI8;
      cnt[tid] = tcntI8;
    }
    { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 113, "./dir_wr_verbs/f1f2_to_s.c"); }; status = (status) ; goto BYE; } } };
    long long final_rslt = 0; long long final_cnt = 0;
    for ( int tid = 0; tid < nT; tid++ ) {
      final_rslt += rslt[tid];
      final_cnt += cnt[tid];
    }
    sprintf(rslt_buf, "%lld:%lld:%lld\n", final_rslt, final_cnt, nR);
  }
 BYE:
  { if ( ( f1_X == ((void *)0) ) && ( f1_nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 122, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( ( f1_X != ((void *)0) ) && ( f1_nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 122, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( f1_X != ((void *)0) ) { munmap(f1_X, f1_nX); f1_X = ((void *)0); f1_nX = 0; } };
  { if ( ( f2_X == ((void *)0) ) && ( f2_nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 123, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( ( f2_X != ((void *)0) ) && ( f2_nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 123, "./dir_wr_verbs/f1f2_to_s.c"); }; return(-1); } if ( f2_X != ((void *)0) ) { munmap(f2_X, f2_nX); f2_X = ((void *)0); f2_nX = 0; } };
  return(status);
}

variable_types:
tbl
char *

variable_types:
op
char *

variable_types: status int

variable_types: struct _TBL_REC_TYPE { long long nR; char name[-1]; char dispname[-1]; _Bool is_dict_tbl; }

variable_types: struct _FLD_REC_TYPE { int tbl_id; int ddir_id; int is_external; enum _SORT_TYPE { unknown=0, ascending=1, descending=2, unsorted=3 } sort_type; int parent_id; int nn_fld_id; enum _FLD_TYPE { xunknown=0, B=1, I1=2, I2=3, I4=4, I8=5, F4=6, F8=7, clob=8 } fldtype; enum _AUX_TYPE { undef=0, nn=1 } auxtype; char name[-1]; char filename[-1]; char dispname[-1]; int dict_tbl_id; int alias_of_fld_id; long long cnt; }

variable_types:
rslt
long long [16]

variable_types:
cnt
long long [16]

variable_types: nT int

variable_types: tid int

variable_types:
lb
long long

variable_types:
ub
long long

variable_types:
tnR
long long


repo: linkedin/datacl

original_code:
void
shiftright2_UI8(
       unsigned long long *in1,
       unsigned long long *in2,
       long long nR,
       unsigned long long * restrict out
       )
{
  unsigned long long inv1, inv2, outv;
  for ( long long i = 0; i < nR; i++ ) {
    inv1 = *in1;
    inv2 = *in2;
    outv = inv1 >> inv2;
    *out = outv;
    in1++;
    in2++;
    out++;
  }
}

canonical_original_code:
void shiftright2_UI8(unsigned long long *in1, unsigned long long *in2, long long nR, unsigned long long *out)
{
  unsigned long long inv1; unsigned long long inv2; unsigned long long outv;
  for ( long long i = 0; i < nR; i++ ) {
    inv1 = *in1;
    inv2 = *in2;
    outv = inv1 >> inv2;
    *out = outv;
    in1++;
    in2++;
    out++;
  }
}

variable_types:
nR
long long

variable_types:
out
unsigned long long *

variable_types:
outv
unsigned long long

variable_types:
i
long long

return_type: void


New

decompiled_code:
__int64 __fastcall New(void *src, void *dest, __int64 a3, int a4, int a5, int a6, __int64 a7)
{
__int64 v8; // rbx
__int64 v11; // rdx

if ( src )
{
if ( dest )
{
if ( a3 )
{
v8 = a5;
if ( a5 >= 0 && a5 < a6 )
{
memcpy(dest, src, 4 * a7);
*(_DWORD *)(a3 + 4 * v8) = a4;
return 0LL;
}
v11 = 53LL;
}
else
{
v11 = 52LL;
}
}
else
{
v11 = 51LL;
}
}
else
{
v11 = 50LL;
}
fprintf(stderr, "Line %3d of File %s \n", v11, "New.c");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src, void *dest, __int64 a3, int a4, int a5, int a6, __int64 a7)
{
__int64 v8; // rbx
__int64 v11; // rdx

if ( src )
{
if ( dest )
{
if ( a3 )
{
v8 = a5;
if ( a5 >= 0 && a5 < a6 )
{
memcpy(dest, src, 4 * a7);
*(_DWORD *)(a3 + 4 * v8) = a4;
return 0LL;
}
v11 = 53LL;
}
else
{
v11 = 52LL;
}
}
else
{
v11 = 51LL;
}
}
else
{
v11 = 50LL;
}
fprintf(stderr, "Line %3d of File %s \n", v11, "New.c");
return 0xFFFFFFFFLL;
}

original_code:
int New(
 int *src_buf,
 int *dst_buf,
 int *ptr_weight,
 int initial_weight,
 int bufidx,
 int b,
 long long k
 )
{
  int status = 0;
  if ( src_buf == ((void *)0) ) { { { fprintf(stderr, "Line %3d of File %s \n", 50, "New.c"); }; status = -1 ; goto BYE; }; }
  if ( dst_buf == ((void *)0) ) { { { fprintf(stderr, "Line %3d of File %s \n", 51, "New.c"); }; status = -1 ; goto BYE; }; }
  if ( ptr_weight == ((void *)0) ) { { { fprintf(stderr, "Line %3d of File %s \n", 52, "New.c"); }; status = -1 ; goto BYE; }; }
  if ( bufidx < 0 || bufidx >= b ) { { { fprintf(stderr, "Line %3d of File %s \n", 53, "New.c"); }; status = -1 ; goto BYE; }; }
  memcpy(dst_buf, src_buf, k * sizeof(int));
  ptr_weight[bufidx] = initial_weight ;
 BYE:
  return(status);
}

canonical_original_code:
int New(int *src_buf, int *dst_buf, int *ptr_weight, int initial_weight, int bufidx, int b, long long k)
{
  int status = 0;
  if ( src_buf == ((void *)0) ) { { { fprintf(stderr, "Line %3d of File %s \n", 50, "New.c"); }; status = -1 ; goto BYE; }; }
  if ( dst_buf == ((void *)0) ) { { { fprintf(stderr, "Line %3d of File %s \n", 51, "New.c"); }; status = -1 ; goto BYE; }; }
  if ( ptr_weight == ((void *)0) ) { { { fprintf(stderr, "Line %3d of File %s \n", 52, "New.c"); }; status = -1 ; goto BYE; }; }
  if ( bufidx < 0 || bufidx >= b ) { { { fprintf(stderr, "Line %3d of File %s \n", 53, "New.c"); }; status = -1 ; goto BYE; }; }
  memcpy(dst_buf, src_buf, k * sizeof(int));
  ptr_weight[bufidx] = initial_weight ;
 BYE:
  return(status);
}

variable_types: bufidx int

variable_types: b int

variable_types:
k
long long

return_type: int


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

if ( a4 > 8 )
result = cmp_eq_mult_scalar_log_I4();
else
result = cmp_eq_mult_scalar_simple_I4();
return result;
}

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

if ( a4 > 8 )
result = cmp_eq_mult_scalar_log_I4();
else
result = cmp_eq_mult_scalar_simple_I4();
return result;
}

original_code:
void
cmp_eq_mult_scalar_I4(
         int *in1,
         long long n1,
         int *in2,
         int n2,
         char * restrict out
          )
{
  if ( n2 <= 8 ) {
    cmp_eq_mult_scalar_simple_I4( in1, n1, in2, n2, out);
  }
  else
    cmp_eq_mult_scalar_log_I4( in1, n1, in2, n2, out);
}

canonical_original_code:
void cmp_eq_mult_scalar_I4(int *in1, long long n1, int *in2, int n2, char *out)
{
  if ( n2 <= 8 ) {
    cmp_eq_mult_scalar_simple_I4( in1, n1, in2, n2, out);
  }
  else
    cmp_eq_mult_scalar_log_I4( in1, n1, in2, n2, out);
}

variable_types:
out
char *


decompiled_code:
__int64 __fastcall set_val(const char *a1, const char *a2, _BYTE *a3, const char *a4)
{
int v6; // er14
__int64 v7; // rdx
__int64 v8; // r15
void **v9; // rdi
__int64 v10; // rbx
__int64 v12; // rdx
__int64 v13; // rax
__int64 v14; // rbp
__int64 v15; // rax
__int64 v16; // r12
__int64 v17; // rdx
int v18; // [rsp+0h] [rbp-2E8h] BYREF
unsigned int v19; // [rsp+4h] [rbp-2E4h] BYREF
int v20; // [rsp+8h] [rbp-2E0h] BYREF
int v21; // [rsp+Ch] [rbp-2DCh] BYREF
void *addr; // [rsp+10h] [rbp-2D8h] BYREF
size_t len; // [rsp+18h] [rbp-2D0h] BYREF
void *v24; // [rsp+20h] [rbp-2C8h] BYREF
size_t v25; // [rsp+28h] [rbp-2C0h] BYREF
void *ptr; // [rsp+30h] [rbp-2B8h] BYREF
char *endptr; // [rsp+38h] [rbp-2B0h] BYREF
__int64 v28[22]; // [rsp+40h] [rbp-2A8h] BYREF
__int64 v29; // [rsp+F0h] [rbp-1F8h] BYREF
__int64 v30; // [rsp+108h] [rbp-1E0h]
__int64 v31; // [rsp+1D0h] [rbp-118h] BYREF

addr = 0LL;
len = 0LL;
v24 = 0LL;
v25 = 0LL;
ptr = 0LL;
v18 = 0;
endptr = 0LL;
if ( !a1 || !*a1 )
{
v7 = 46LL;
goto LABEL_20;
}
if ( !a2 || !*a2 )
{
v7 = 47LL;
goto LABEL_20;
}
if ( !a3 || !*a3 )
{
v7 = 48LL;
goto LABEL_20;
}
if ( !a4 || !*a4 )
{
v7 = 49LL;
goto LABEL_20;
}
v6 = is_tbl(a1, &v19, v28);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 51LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
v7 = 52LL;
if ( (v19 & 0x80000000) != 0 )
goto LABEL_20;
v8 = v28[0];
v6 = is_fld(0LL, v19, a2, &v20, &v29, &v21, &v31);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 55LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
if ( v20 < 0 )
{
fprintf(stderr, "Field [%s] not in Table [%s] \n", a2, a1);
v7 = 58LL;
goto LABEL_20;
}
v6 = get_data(&addr, &len, 1LL);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 61LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
if ( v21 >= 0 )
{
v6 = get_data(&v24, &v25, 1LL);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 64LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
}
v6 = explode(a3, 58LL, &ptr, &v18);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 67LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
if ( v18 != 2 )
{
v7 = 68LL;
goto LABEL_20;
}
v13 = strtoll(*(const char **)ptr, &endptr, 10);
v7 = 71LL;
v14 = v13;
if ( *endptr )
goto LABEL_20;
if ( v13 < 0 || v8 <= v13 )
{
v7 = 72LL;
goto LABEL_20;
}
v15 = strtoll(*((const char **)ptr + 1), &endptr, 10);
v7 = 75LL;
v16 = v15;
if ( *endptr )
goto LABEL_20;
if ( v15 < 0 || v8 < v15 )
{
v7 = 76LL;
goto LABEL_20;
}
v7 = 77LL;
if ( v14 >= v15 )
{
LABEL_20:
v6 = -1;
fprintf(stderr, "Line %3d of File %s \n", v7, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
v17 = strtoll(a4, &endptr, 10);
if ( *endptr )
{
v7 = 80LL;
goto LABEL_20;
}
switch ( (_DWORD)v30 )
{
case 4:
if ( (unsigned __int64)(v17 + 0x80000000LL) > 0xFFFFFFFF )
{
v7 = 90LL;
goto LABEL_20;
}
assign_const_I4((char *)addr + 4 * v14, v16 - v14);
break;
case 5:
assign_const_I8((char *)addr + 8 * v14, v16 - v14, v17);
break;
case 2:
if ( (unsigned __int64)(v17 + 128) > 0xFF )
{
v7 = 85LL;
goto LABEL_20;
}
assign_const_I1((char *)addr + v14, v16 - v14);
break;
default:
v7 = 98LL;
goto LABEL_20;
}
if ( v24 )
assign_const_I1((char *)v24 + v14, v16 - v14);
LABEL_21:
v9 = (void **)ptr;
if ( ptr )
{
if ( v18 <= 0 )
goto LABEL_28;
v10 = 0LL;
do
{
if ( v9[v10] )
{
free(v9[v10]);
v9 = (void **)ptr;
*((_QWORD *)ptr + v10) = 0LL;
}
++v10;
}
while ( v18 > (int)v10 );
if ( v9 )
{
LABEL_28:
free(v9);
ptr = 0LL;
}
}
if ( addr )
{
if ( len )
{
munmap(addr, len);
addr = 0LL;
len = 0LL;
goto LABEL_32;
}
LABEL_38:
v12 = 113LL;
LABEL_39:
v6 = -1;
fprintf(stderr, "Line %3d of File %s \n", v12, "./dir_wr_verbs/set_val.c");
return (unsigned int)v6;
}
if ( len )
goto LABEL_38;
LABEL_32:
if ( !v24 )
{
if ( !v25 )
return (unsigned int)v6;
goto LABEL_41;
}
if ( !v25 )
{
LABEL_41:
v12 = 114LL;
goto LABEL_39;
}
munmap(v24, v25);
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2, _BYTE *a3, const char *a4)
{
int v6; // er14
__int64 v7; // rdx
__int64 v8; // r15
void **v9; // rdi
__int64 v10; // rbx
__int64 v12; // rdx
__int64 v13; // rax
__int64 v14; // rbp
__int64 v15; // rax
__int64 v16; // r12
__int64 v17; // rdx
int v18; // [rsp+0h] [rbp-2E8h] BYREF
unsigned int v19; // [rsp+4h] [rbp-2E4h] BYREF
int v20; // [rsp+8h] [rbp-2E0h] BYREF
int v21; // [rsp+Ch] [rbp-2DCh] BYREF
void *addr; // [rsp+10h] [rbp-2D8h] BYREF
size_t len; // [rsp+18h] [rbp-2D0h] BYREF
void *v24; // [rsp+20h] [rbp-2C8h] BYREF
size_t v25; // [rsp+28h] [rbp-2C0h] BYREF
void *ptr; // [rsp+30h] [rbp-2B8h] BYREF
char *endptr; // [rsp+38h] [rbp-2B0h] BYREF
__int64 v28[22]; // [rsp+40h] [rbp-2A8h] BYREF
__int64 v29; // [rsp+F0h] [rbp-1F8h] BYREF
__int64 v30; // [rsp+108h] [rbp-1E0h]
__int64 v31; // [rsp+1D0h] [rbp-118h] BYREF

addr = 0LL;
len = 0LL;
v24 = 0LL;
v25 = 0LL;
ptr = 0LL;
v18 = 0;
endptr = 0LL;
if ( !a1 || !*a1 )
{
v7 = 46LL;
goto LABEL_20;
}
if ( !a2 || !*a2 )
{
v7 = 47LL;
goto LABEL_20;
}
if ( !a3 || !*a3 )
{
v7 = 48LL;
goto LABEL_20;
}
if ( !a4 || !*a4 )
{
v7 = 49LL;
goto LABEL_20;
}
v6 = is_tbl(a1, &v19, v28);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 51LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
v7 = 52LL;
if ( (v19 & 0x80000000) != 0 )
goto LABEL_20;
v8 = v28[0];
v6 = is_fld(0LL, v19, a2, &v20, &v29, &v21, &v31);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 55LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
if ( v20 < 0 )
{
fprintf(stderr, "Field [%s] not in Table [%s] \n", a2, a1);
v7 = 58LL;
goto LABEL_20;
}
v6 = get_data(&addr, &len, 1LL);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 61LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
if ( v21 >= 0 )
{
v6 = get_data(&v24, &v25, 1LL);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 64LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
}
v6 = explode(a3, 58LL, &ptr, &v18);
if ( v6 < 0 )
{
fprintf(stderr, "Line %3d of File %s \n", 67LL, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
if ( v18 != 2 )
{
v7 = 68LL;
goto LABEL_20;
}
v13 = strtoll(*(const char **)ptr, &endptr, 10);
v7 = 71LL;
v14 = v13;
if ( *endptr )
goto LABEL_20;
if ( v13 < 0 || v8 <= v13 )
{
v7 = 72LL;
goto LABEL_20;
}
v15 = strtoll(*((const char **)ptr + 1), &endptr, 10);
v7 = 75LL;
v16 = v15;
if ( *endptr )
goto LABEL_20;
if ( v15 < 0 || v8 < v15 )
{
v7 = 76LL;
goto LABEL_20;
}
v7 = 77LL;
if ( v14 >= v15 )
{
LABEL_20:
v6 = -1;
fprintf(stderr, "Line %3d of File %s \n", v7, "./dir_wr_verbs/set_val.c");
goto LABEL_21;
}
v17 = strtoll(a4, &endptr, 10);
if ( *endptr )
{
v7 = 80LL;
goto LABEL_20;
}
switch ( (_DWORD)v30 )
{
case 4:
if ( (unsigned __int64)(v17 + 0x80000000LL) > 0xFFFFFFFF )
{
v7 = 90LL;
goto LABEL_20;
}
assign_const_I4((char *)addr + 4 * v14, v16 - v14);
break;
case 5:
assign_const_I8((char *)addr + 8 * v14, v16 - v14, v17);
break;
case 2:
if ( (unsigned __int64)(v17 + 128) > 0xFF )
{
v7 = 85LL;
goto LABEL_20;
}
assign_const_I1((char *)addr + v14, v16 - v14);
break;
default:
v7 = 98LL;
goto LABEL_20;
}
if ( v24 )
assign_const_I1((char *)v24 + v14, v16 - v14);
LABEL_21:
v9 = (void **)ptr;
if ( ptr )
{
if ( v18 <= 0 )
goto LABEL_28;
v10 = 0LL;
do
{
if ( v9[v10] )
{
free(v9[v10]);
v9 = (void **)ptr;
*((_QWORD *)ptr + v10) = 0LL;
}
++v10;
}
while ( v18 > (int)v10 );
if ( v9 )
{
LABEL_28:
free(v9);
ptr = 0LL;
}
}
if ( addr )
{
if ( len )
{
munmap(addr, len);
addr = 0LL;
len = 0LL;
goto LABEL_32;
}
LABEL_38:
v12 = 113LL;
LABEL_39:
v6 = -1;
fprintf(stderr, "Line %3d of File %s \n", v12, "./dir_wr_verbs/set_val.c");
return (unsigned int)v6;
}
if ( len )
goto LABEL_38;
LABEL_32:
if ( !v24 )
{
if ( !v25 )
return (unsigned int)v6;
goto LABEL_41;
}
if ( !v25 )
{
LABEL_41:
v12 = 114LL;
goto LABEL_39;
}
munmap(v24, v25);
return (unsigned int)v6;
}

original_code:
int
set_val(
       char *tbl,
       char *fld,
       char *str_range,
       char *str_val
       )
{
  int status = 0;
  TBL_REC_TYPE tbl_rec;
  FLD_REC_TYPE fld_rec, nn_fld_rec;
  char *X = ((void *)0); size_t nX = 0;
  char *nn_X = ((void *)0); size_t nn_nX = 0;
  char **Y = ((void *)0); int nY = 0;
  char *I1ptr = ((void *)0); int *I4ptr = ((void *)0); long long *I8ptr = ((void *)0);
  int tbl_id, fld_id, nn_fld_id;
  long long nR;
  char *endptr = ((void *)0);
  if ( ( tbl == ((void *)0) ) || ( *tbl == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 46, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  if ( ( fld == ((void *)0) ) || ( *fld == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 47, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  if ( ( str_range == ((void *)0) ) || ( *str_range == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 48, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  if ( ( str_val == ((void *)0) ) || ( *str_val == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 49, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  status = is_tbl(tbl, &tbl_id, &tbl_rec); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 51, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( tbl_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 52, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  nR = tbl_rec.nR;
  status = is_fld(((void *)0), tbl_id, fld, &fld_id, &fld_rec, &nn_fld_id, &nn_fld_rec); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 55, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( fld_id < 0 ) {
    fprintf(stderr, "Field [%s] not in Table [%s] \n", fld, tbl);
    { { fprintf(stderr, "Line %3d of File %s \n", 58, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; };
  }
  status = get_data(fld_rec, &X, &nX, 1); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 61, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( nn_fld_id >= 0 ) {
    status = get_data(nn_fld_rec, &nn_X, &nn_nX, 1); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 64, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  }
  status = explode(str_range, ':', &Y, &nY); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 67, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( nY != 2 ) { { { fprintf(stderr, "Line %3d of File %s \n", 68, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  long long lb = strtoll(Y[0], &endptr, 10);
  if ( *endptr != '\0' ) { { { fprintf(stderr, "Line %3d of File %s \n", 71, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  { if ( ( (lb) < (0) ) || ( (lb) >= (nR ) ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 72, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; } };
  long long ub = strtoll(Y[1], &endptr, 10);
  if ( *endptr != '\0' ) { { { fprintf(stderr, "Line %3d of File %s \n", 75, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  { if ( ( (ub) < (0) ) || ( (ub) >= (nR+1 ) ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 76, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; } };
  if ( lb >= ub ) { { { fprintf(stderr, "Line %3d of File %s \n", 77, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  long long I8val = strtoll(str_val, &endptr, 10);
  if ( *endptr != '\0' ) { { { fprintf(stderr, "Line %3d of File %s \n", 80, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  switch ( fld_rec.fldtype ) {
    case I1 :
      I1ptr = (char *)X;
      if ( ( I8val < (-0x7f - 1) ) || (I8val > 0x7f ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 85, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
      assign_const_I1(I1ptr + lb, (ub-lb), (int)I8val);
      break;
    case I4 :
      I4ptr = (int*)X;
      if ( ( I8val < (-0x7fffffff - 1) ) || (I8val > 0x7fffffff ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 90, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
      assign_const_I4(I4ptr + lb, (ub-lb), (int)I8val);
      break;
    case I8 :
      I8ptr = (long long*)X;
      assign_const_I8(I8ptr + lb, (ub-lb), I8val);
      break;
    default :
      { { fprintf(stderr, "Line %3d of File %s \n", 98, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; };
      break;
  }
  if ( nn_X != ((void *)0) ) {
    assign_const_I1(nn_X + lb, (ub-lb), 1);
  }
 BYE:
  if ( Y != ((void *)0) ) {
    for ( int i = 0; i < nY; i++ ) {
      { if ( (Y[i]) != ((void *)0) ) { free((Y[i])); (Y[i]) = ((void *)0); } };
    }
    { if ( (Y) != ((void *)0) ) { free((Y)); (Y) = ((void *)0); } };
  }
  { if ( ( X == ((void *)0) ) && ( nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 113, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( ( X != ((void *)0) ) && ( nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 113, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( X != ((void *)0) ) { munmap(X, nX); X = ((void *)0); nX = 0; } };
  { if ( ( nn_X == ((void *)0) ) && ( nn_nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 114, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( ( nn_X != ((void *)0) ) && ( nn_nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 114, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( nn_X != ((void *)0) ) { munmap(nn_X, nn_nX); nn_X = ((void *)0); nn_nX = 0; } };
  return(status);
}

canonical_original_code:
int set_val(char *tbl, char *fld, char *str_range, char *str_val)
{
  int status = 0;
  struct _TBL_REC_TYPE tbl_rec;
  struct _FLD_REC_TYPE fld_rec; struct _FLD_REC_TYPE nn_fld_rec;
  char *X = ((void *)0); unsigned long nX = 0;
  char *nn_X = ((void *)0); unsigned long nn_nX = 0;
  char **Y = ((void *)0); int nY = 0;
  char *I1ptr = ((void *)0); int *I4ptr = ((void *)0); long long *I8ptr = ((void *)0);
  int tbl_id; int fld_id; int nn_fld_id;
  long long nR;
  char *endptr = ((void *)0);
  if ( ( tbl == ((void *)0) ) || ( *tbl == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 46, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  if ( ( fld == ((void *)0) ) || ( *fld == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 47, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  if ( ( str_range == ((void *)0) ) || ( *str_range == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 48, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  if ( ( str_val == ((void *)0) ) || ( *str_val == '\0' ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 49, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  status = is_tbl(tbl, &tbl_id, &tbl_rec); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 51, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( tbl_id < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 52, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  nR = tbl_rec.nR;
  status = is_fld(((void *)0), tbl_id, fld, &fld_id, &fld_rec, &nn_fld_id, &nn_fld_rec); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 55, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( fld_id < 0 ) {
    fprintf(stderr, "Field [%s] not in Table [%s] \n", fld, tbl);
    { { fprintf(stderr, "Line %3d of File %s \n", 58, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; };
  }
  status = get_data(fld_rec, &X, &nX, 1); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 61, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( nn_fld_id >= 0 ) {
    status = get_data(nn_fld_rec, &nn_X, &nn_nX, 1); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 64, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  }
  status = explode(str_range, ':', &Y, &nY); { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 67, "./dir_wr_verbs/set_val.c"); }; status = (status) ; goto BYE; } } };
  if ( nY != 2 ) { { { fprintf(stderr, "Line %3d of File %s \n", 68, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  long long lb = strtoll(Y[0], &endptr, 10);
  if ( *endptr != '\0' ) { { { fprintf(stderr, "Line %3d of File %s \n", 71, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  { if ( ( (lb) < (0) ) || ( (lb) >= (nR ) ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 72, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; } };
  long long ub = strtoll(Y[1], &endptr, 10);
  if ( *endptr != '\0' ) { { { fprintf(stderr, "Line %3d of File %s \n", 75, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  { if ( ( (ub) < (0) ) || ( (ub) >= (nR+1 ) ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 76, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; } };
  if ( lb >= ub ) { { { fprintf(stderr, "Line %3d of File %s \n", 77, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  long long I8val = strtoll(str_val, &endptr, 10);
  if ( *endptr != '\0' ) { { { fprintf(stderr, "Line %3d of File %s \n", 80, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
  switch ( fld_rec.fldtype ) {
    case I1 :
      I1ptr = (char *)X;
      if ( ( I8val < (-0x7f - 1) ) || (I8val > 0x7f ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 85, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
      assign_const_I1(I1ptr + lb, (ub-lb), (int)I8val);
      break;
    case I4 :
      I4ptr = (int *)X;
      if ( ( I8val < (-0x7fffffff - 1) ) || (I8val > 0x7fffffff ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 90, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; }; }
      assign_const_I4(I4ptr + lb, (ub-lb), (int)I8val);
      break;
    case I8 :
      I8ptr = (long long *)X;
      assign_const_I8(I8ptr + lb, (ub-lb), I8val);
      break;
    default :
      { { fprintf(stderr, "Line %3d of File %s \n", 98, "./dir_wr_verbs/set_val.c"); }; status = -1 ; goto BYE; };
      break;
  }
  if ( nn_X != ((void *)0) ) {
    assign_const_I1(nn_X + lb, (ub-lb), 1);
  }
 BYE:
  if ( Y != ((void *)0) ) {
    for ( int i = 0; i < nY; i++ ) {
      { if ( (Y[i]) != ((void *)0) ) { free((Y[i])); (Y[i]) = ((void *)0); } };
    }
    { if ( (Y) != ((void *)0) ) { free((Y)); (Y) = ((void *)0); } };
  }
  { if ( ( X == ((void *)0) ) && ( nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 113, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( ( X != ((void *)0) ) && ( nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 113, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( X != ((void *)0) ) { munmap(X, nX); X = ((void *)0); nX = 0; } };
  { if ( ( nn_X == ((void *)0) ) && ( nn_nX != 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 114, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( ( nn_X != ((void *)0) ) && ( nn_nX == 0 ) ) { { fprintf(stderr, "Line %3d of File %s \n", 114, "./dir_wr_verbs/set_val.c"); }; return(-1); } if ( nn_X != ((void *)0) ) { munmap(nn_X, nn_nX); nn_X = ((void *)0); nn_nX = 0; } };
  return(status);
}

variable_types:
tbl
char *

variable_types:
fld
char *

variable_types: status int

variable_types: struct _TBL_REC_TYPE { long long nR; char name[-1]; char dispname[-1]; _Bool is_dict_tbl; }

variable_types:
X
char *

variable_types:
nX
unsigned long

variable_types:
Y
char **

variable_types: nY int

variable_types:
endptr
char *

variable_types: i int

user_defined_types: struct _FLD_REC_TYPE { int tbl_id; int ddir_id; int is_external; enum _SORT_TYPE sort_type; int parent_id; int nn_fld_id; enum _FLD_TYPE fldtype; enum _AUX_TYPE auxtype; char name[-1]; char filename[-1]; char dispname[-1]; int dict_tbl_id; int alias_of_fld_id; long long cnt; }

user_defined_types: enum _SORT_TYPE { unknown=0, ascending=1, descending=2, unsorted=3 }


original_code:
int
core_srt_join_L_L_I(
          long long *src_lnk,
          long long *src_val,
          long long src_nR,
          int *dst_lnk,
          long long *dst_val,
          char *nn_dst_val,
          long long dst_lb,
          long long dst_ub,
          int ijoin_op,
          _Bool *ptr_is_any_null
          )
{
  int status = 0;
  long long src_idx;
  int v_dst_lnk;
  long long v_src_val;
  long long v_src_lnk;
  _Bool found, prev_val_known = 0;
  status = set_init(nn_dst_val, dst_val, dst_lb, dst_ub, ijoin_op);
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 117, "./AUX/core_srt_join_L_L_I.c"); }; status = (status) ; goto BYE; } } };
  src_idx = 0;
  for ( long long dst_idx = dst_lb; dst_idx < dst_ub; dst_idx++ ) {
    v_dst_lnk = dst_lnk[dst_idx];
    if ( dst_idx > 0 ) {
      if ( v_dst_lnk == dst_lnk[dst_idx-1] ) {
 if ( dst_val != ((void *)0) ) {
   dst_val[dst_idx] = dst_val[dst_idx-1];
 }
        nn_dst_val[dst_idx] = nn_dst_val[dst_idx-1];
        continue;
      }
    }
    found = 0;
    for ( ; src_idx < src_nR; ) {
      v_src_lnk = src_lnk[src_idx];
      if ( v_src_lnk == v_dst_lnk ) {
 found = 1;
 prev_val_known = 1;
 break;
      }
      else if ( v_src_lnk > v_dst_lnk ) {
 if ( *ptr_is_any_null == 0 ) {
          *ptr_is_any_null = 1;
 }
 found = 0;
 break;
      }
      long long delta = 1;
      long long expt_src_idx, prev_expt_src_idx;
      prev_expt_src_idx = src_idx + delta;
      for ( ; ; ) {
        expt_src_idx = src_idx + delta;
 if ( expt_src_idx >= src_nR ) {
   expt_src_idx = prev_expt_src_idx;
   break;
 }
        v_src_lnk = src_lnk[expt_src_idx];
        if ( v_src_lnk >= v_dst_lnk ) {
   expt_src_idx = prev_expt_src_idx;
   break;
        }
 else if ( v_src_lnk < v_dst_lnk ) {
   delta *= 2;
          prev_expt_src_idx = expt_src_idx;
        }
      }
      src_idx = expt_src_idx;
    }
    if ( found == 1 ) {
      nn_dst_val[dst_idx] = 1;
      for ( ; src_idx < src_nR; src_idx++ ) {
        v_src_lnk = src_lnk[src_idx];
 if ( v_src_lnk != v_dst_lnk ) {
   src_idx--;
   break;
 }
 if ( src_val != ((void *)0) ) {
   v_src_val = src_val[src_idx];
   switch ( ijoin_op ) {
   case 100 :
     dst_val[dst_idx] += v_src_val;
     break;
   case 300 :
     if ( v_src_val > dst_val[dst_idx] ) {
       dst_val[dst_idx] = v_src_val;
     }
     break;
   case 200 :
     if ( v_src_val < dst_val[dst_idx] ) {
       dst_val[dst_idx] = v_src_val;
     }
     break;
   case 600 :
     dst_val[dst_idx] |= v_src_val;
     break;
   case 700 :
     dst_val[dst_idx] &= v_src_val;
     break;
   case 500 :
     dst_val[dst_idx] = v_src_val;
     break;
   default :
     { { fprintf(stderr, "Line %3d of File %s \n", 216, "./AUX/core_srt_join_L_L_I.c"); }; status = -1 ; goto BYE; };
     break;
   }
 }
 else {
   if ( ijoin_op == 800 ) {
            dst_val[dst_idx] += 1;
   }
 }
      }
    }
    else {
      if ( *ptr_is_any_null == 0 ) {
        *ptr_is_any_null = 1;
      }
      nn_dst_val[dst_idx] = 0;
    }
  }
  if ( *ptr_is_any_null ) {
    for ( long long dst_idx = dst_lb; dst_idx < dst_ub; dst_idx++ ) {
      if ( nn_dst_val[dst_idx] == 0 ) {
 dst_val[dst_idx] = 0;
      }
    }
  }
 BYE:
  return(status);
}

canonical_original_code:
int core_srt_join_L_L_I(long long *src_lnk, long long *src_val, long long src_nR, int *dst_lnk, long long *dst_val, char *nn_dst_val, long long dst_lb, long long dst_ub, int ijoin_op, _Bool *ptr_is_any_null)
{
  int status = 0;
  long long src_idx;
  int v_dst_lnk;
  long long v_src_val;
  long long v_src_lnk;
  _Bool found; _Bool prev_val_known = 0;
  status = set_init(nn_dst_val, dst_val, dst_lb, dst_ub, ijoin_op);
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 117, "./AUX/core_srt_join_L_L_I.c"); }; status = (status) ; goto BYE; } } };
  src_idx = 0;
  for ( long long dst_idx = dst_lb; dst_idx < dst_ub; dst_idx++ ) {
    v_dst_lnk = dst_lnk[dst_idx];
    if ( dst_idx > 0 ) {
      if ( v_dst_lnk == dst_lnk[dst_idx-1] ) {
 if ( dst_val != ((void *)0) ) {
   dst_val[dst_idx] = dst_val[dst_idx-1];
 }
        nn_dst_val[dst_idx] = nn_dst_val[dst_idx-1];
        continue;
      }
    }
    found = 0;
    for ( ; src_idx < src_nR; ) {
      v_src_lnk = src_lnk[src_idx];
      if ( v_src_lnk == v_dst_lnk ) {
 found = 1;
 prev_val_known = 1;
 break;
      }
      else if ( v_src_lnk > v_dst_lnk ) {
 if ( *ptr_is_any_null == 0 ) {
          *ptr_is_any_null = 1;
 }
 found = 0;
 break;
      }
      long long delta = 1;
      long long expt_src_idx; long long prev_expt_src_idx;
      prev_expt_src_idx = src_idx + delta;
      for ( ; ; ) {
        expt_src_idx = src_idx + delta;
 if ( expt_src_idx >= src_nR ) {
   expt_src_idx = prev_expt_src_idx;
   break;
 }
        v_src_lnk = src_lnk[expt_src_idx];
        if ( v_src_lnk >= v_dst_lnk ) {
   expt_src_idx = prev_expt_src_idx;
   break;
        }
 else if ( v_src_lnk < v_dst_lnk ) {
   delta *= 2;
          prev_expt_src_idx = expt_src_idx;
        }
      }
      src_idx = expt_src_idx;
    }
    if ( found == 1 ) {
      nn_dst_val[dst_idx] = 1;
      for ( ; src_idx < src_nR; src_idx++ ) {
        v_src_lnk = src_lnk[src_idx];
 if ( v_src_lnk != v_dst_lnk ) {
   src_idx--;
   break;
 }
 if ( src_val != ((void *)0) ) {
   v_src_val = src_val[src_idx];
   switch ( ijoin_op ) {
   case 100 :
     dst_val[dst_idx] += v_src_val;
     break;
   case 300 :
     if ( v_src_val > dst_val[dst_idx] ) {
       dst_val[dst_idx] = v_src_val;
     }
     break;
   case 200 :
     if ( v_src_val < dst_val[dst_idx] ) {
       dst_val[dst_idx] = v_src_val;
     }
     break;
   case 600 :
     dst_val[dst_idx] |= v_src_val;
     break;
   case 700 :
     dst_val[dst_idx] &= v_src_val;
     break;
   case 500 :
     dst_val[dst_idx] = v_src_val;
     break;
   default :
     { { fprintf(stderr, "Line %3d of File %s \n", 216, "./AUX/core_srt_join_L_L_I.c"); }; status = -1 ; goto BYE; };
     break;
   }
 }
 else {
   if ( ijoin_op == 800 ) {
            dst_val[dst_idx] += 1;
   }
 }
      }
    }
    else {
      if ( *ptr_is_any_null == 0 ) {
        *ptr_is_any_null = 1;
      }
      nn_dst_val[dst_idx] = 0;
    }
  }
  if ( *ptr_is_any_null ) {
    for ( long long dst_idx = dst_lb; dst_idx < dst_ub; dst_idx++ ) {
      if ( nn_dst_val[dst_idx] == 0 ) {
 dst_val[dst_idx] = 0;
      }
    }
  }
 BYE:
  return(status);
}

variable_types:
delta
long long


decompiled_code:
__int64 __fastcall set_init(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
__int64 v8; // rdi

assign_const_I1(a3 + a1, 0LL, (unsigned int)(char)(a4 - a3));
if ( !a2 )
return 0LL;
v8 = a2 + 8 * a3;
if ( a5 == 300 )
{
assign_const_I8(v8, 0x8000000000000000LL, a4 - a3);
return 0LL;
}
if ( a5 <= 300 )
{
if ( a5 == 100 )
{
LABEL_14:
assign_const_I8(v8, 0LL, a4 - a3);
return 0LL;
}
if ( a5 != 200 )
goto LABEL_7;
assign_const_I8(v8, 0x7FFFFFFFFFFFFFFFLL, a4 - a3);
return 0LL;
}
if ( a5 != 700 )
{
if ( a5 <= 700 )
{
if ( a5 != 500 && a5 != 600 )
goto LABEL_7;
}
else if ( a5 != 800 )
{
LABEL_7:
fprintf(stderr, "Line %3d of File %s \n", 67LL, "./AUX/core_srt_join_L_L_I.c");
return 0xFFFFFFFFLL;
}
goto LABEL_14;
}
assign_const_I8(v8, -1LL, a4 - a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
__int64 v8; // rdi

assign_const_I1(a3 + a1, 0LL, (unsigned int)(char)(a4 - a3));
if ( !a2 )
return 0LL;
v8 = a2 + 8 * a3;
if ( a5 == 300 )
{
assign_const_I8(v8, 0x8000000000000000LL, a4 - a3);
return 0LL;
}
if ( a5 <= 300 )
{
if ( a5 == 100 )
{
LABEL_14:
assign_const_I8(v8, 0LL, a4 - a3);
return 0LL;
}
if ( a5 != 200 )
goto LABEL_7;
assign_const_I8(v8, 0x7FFFFFFFFFFFFFFFLL, a4 - a3);
return 0LL;
}
if ( a5 != 700 )
{
if ( a5 <= 700 )
{
if ( a5 != 500 && a5 != 600 )
goto LABEL_7;
}
else if ( a5 != 800 )
{
LABEL_7:
fprintf(stderr, "Line %3d of File %s \n", 67LL, "./AUX/core_srt_join_L_L_I.c");
return 0xFFFFFFFFLL;
}
goto LABEL_14;
}
assign_const_I8(v8, -1LL, a4 - a3);
return 0LL;
}

original_code:
static int
set_init(
  char *nn_dst_val,
  long long *dst_val,
  long long lb,
  long long ub,
  int ijoin_op
  )
{
  int status = 0;
  assign_const_I1(nn_dst_val+lb, 0, (ub-lb));
  if ( dst_val != ((void *)0) ) {
    long long *this_dst_val = dst_val;
    this_dst_val += lb;
    switch ( ijoin_op ) {
    case 500 :
    case 100 :
    case 800 :
    case 600 :
      assign_const_I8(this_dst_val, 0, (ub-lb));
      break;
    case 700 :
      assign_const_I8(this_dst_val, 0xFFFFFFFFFFFFFFFF, (ub-lb));
      break;
    case 200 :
      assign_const_I8(this_dst_val, 0x7fffffffffffffffLL, (ub-lb));
      break;
    case 300 :
      assign_const_I8(this_dst_val, (-0x7fffffffffffffffLL - 1LL), (ub-lb));
      break;
    default :
      { { fprintf(stderr, "Line %3d of File %s \n", 67, "./AUX/core_srt_join_L_L_I.c"); }; status = -1 ; goto BYE; };
      break;
    }
  }
 BYE:
  return(status);
}

canonical_original_code:
static int set_init(char *nn_dst_val, long long *dst_val, long long lb, long long ub, int ijoin_op)
{
  int status = 0;
  assign_const_I1(nn_dst_val+lb, 0, (ub-lb));
  if ( dst_val != ((void *)0) ) {
    long long *this_dst_val = dst_val;
    this_dst_val += lb;
    switch ( ijoin_op ) {
    case 500 :
    case 100 :
    case 800 :
    case 600 :
      assign_const_I8(this_dst_val, 0, (ub-lb));
      break;
    case 700 :
      assign_const_I8(this_dst_val, 0xFFFFFFFFFFFFFFFF, (ub-lb));
      break;
    case 200 :
      assign_const_I8(this_dst_val, 0x7fffffffffffffffLL, (ub-lb));
      break;
    case 300 :
      assign_const_I8(this_dst_val, (-0x7fffffffffffffffLL - 1LL), (ub-lb));
      break;
    default :
      { { fprintf(stderr, "Line %3d of File %s \n", 67, "./AUX/core_srt_join_L_L_I.c"); }; status = -1 ; goto BYE; };
      break;
    }
  }
 BYE:
  return(status);
}

variable_types:
lb
long long

variable_types:
ub
long long


decompiled_code:
__int64 __fastcall determine_b_k(__int64 a1, int *a2, __int64 *a3, double a4)
{
int v5; // ebx
double v6; // xmm3_8
double v7; // xmm0_8
int v8; // ebx
__int64 v9; // rax
double y; // [rsp+0h] [rbp-40h]
double v12; // [rsp+8h] [rbp-38h]

v5 = 2;
v6 = LC0;
v12 = (double)(int)a1;
while ( 1 )
{
y = (double)(v5 - 2);
v7 = pow(v6, y);
v6 = LC0;
if ( v12 * a4 <= v7 * y + 1.0 )
break;
++v5;
}
v8 = v5 - 1;
if ( a1 % (unsigned int)(int)pow(2.0, y) )
v9 = (unsigned int)(int)(v12 / pow(2.0, y) + 1.0);
else
v9 = (unsigned int)(int)(v12 / pow(2.0, y));
*a2 = v8;
if ( v9 < 10000 )
v9 = 10000LL;
*a3 = v9;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2, __int64 *a3, double a4)
{
int v5; // ebx
double v6; // xmm3_8
double v7; // xmm0_8
int v8; // ebx
__int64 v9; // rax
double y; // [rsp+0h] [rbp-40h]
double v12; // [rsp+8h] [rbp-38h]

v5 = 2;
v6 = LC0;
v12 = (double)(int)a1;
while ( 1 )
{
y = (double)(v5 - 2);
v7 = pow(v6, y);
v6 = LC0;
if ( v12 * a4 <= v7 * y + 1.0 )
break;
++v5;
}
v8 = v5 - 1;
if ( a1 % (unsigned int)(int)pow(2.0, y) )
v9 = (unsigned int)(int)(v12 / pow(2.0, y) + 1.0);
else
v9 = (unsigned int)(int)(v12 / pow(2.0, y));
*a2 = v8;
if ( v9 < 10000 )
v9 = 10000LL;
*a3 = v9;
return 0LL;
}

original_code:
int
determine_b_k(
       double eps,
       long long siz,
       int *ptr_b,
       long long *ptr_k
       )
{
  int status = 0;
  int b = -1;
  long long k = -1;
  b = 2;
  while ( ((b-2)*pow(2,b-2)+1) < (double)(eps*siz) ) {
    b++;
  }
  b--;
  if ( (siz % (long long)pow(2,b-1)) == 0 ) {
    k = siz/pow(2,b-1);
  }
  else {
    k = siz/pow(2,b-1)+1;
  }
  if ( k < 10000 ) { k = 10000; }
  *ptr_b = b;
  *ptr_k = k;
  return status ;
}

canonical_original_code:
int determine_b_k(double eps, long long siz, int *ptr_b, long long *ptr_k)
{
  int status = 0;
  int b = -1;
  long long k = -1;
  b = 2;
  while ( ((b-2)*pow(2,b-2)+1) < (double)(eps*siz) ) {
    b++;
  }
  b--;
  if ( (siz % (long long)pow(2,b-1)) == 0 ) {
    k = siz/pow(2,b-1);
  }
  else {
    k = siz/pow(2,b-1)+1;
  }
  if ( k < 10000 ) { k = 10000; }
  *ptr_b = b;
  *ptr_k = k;
  return status ;
}

variable_types: eps double

variable_types:
siz
long long


original_code:
void
rem2_I8(
       long long *in1,
       long long *in2,
       long long nR,
       long long * restrict out
       )
{
  long long inv1, inv2, outv;
  for ( long long i = 0; i < nR; i++ ) {
    inv1 = *in1;
    inv2 = *in2;
    outv = inv1 % inv2;
    *out = outv;
    in1++;
    in2++;
    out++;
  }
}

canonical_original_code:
void rem2_I8(long long *in1, long long *in2, long long nR, long long *out)
{
  long long inv1; long long inv2; long long outv;
  for ( long long i = 0; i < nR; i++ ) {
    inv1 = *in1;
    inv2 = *in2;
    outv = inv1 % inv2;
    *out = outv;
    in1++;
    in2++;
    out++;
  }
}

variable_types:
nR
long long

variable_types:
out
long long *

variable_types:
outv
long long

variable_types:
i
long long


original_code:
int
pos_mmad_I8_I8(
    long long *f1,
    long long nR1,
    long long *f2,
    long long nR2,
    long long *ptr_minval,
    long long *ptr_maxval,
    long long *ptr_sum
    )
{
  int status = 0;
  long long minval = *ptr_minval;
  long long maxval = *ptr_maxval;
  long long sum = *ptr_sum;
  for ( long long i = 0; i < nR2; i++ ) {
    long long f1idx = f2[i];
    if ( ( f1idx < 0 ) || ( f1idx >= nR1 ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 36, "./AUX/pos_mmad_I8_I8.c"); }; status = -1 ; goto BYE; }; }
    long long f1val = f1[f1idx];
    if ( f1val < minval ) { minval = f1val; }
    if ( f1val > maxval ) { maxval = f1val; }
    sum += (long long)f1val;
  }
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 43, "./AUX/pos_mmad_I8_I8.c"); }; status = (status) ; goto BYE; } } };
  *ptr_minval = minval;
  *ptr_maxval = maxval;
  *ptr_sum = sum;
BYE:
  return(status);
}

canonical_original_code:
int pos_mmad_I8_I8(long long *f1, long long nR1, long long *f2, long long nR2, long long *ptr_minval, long long *ptr_maxval, long long *ptr_sum)
{
  int status = 0;
  long long minval = *ptr_minval;
  long long maxval = *ptr_maxval;
  long long sum = *ptr_sum;
  for ( long long i = 0; i < nR2; i++ ) {
    long long f1idx = f2[i];
    if ( ( f1idx < 0 ) || ( f1idx >= nR1 ) ) { { { fprintf(stderr, "Line %3d of File %s \n", 36, "./AUX/pos_mmad_I8_I8.c"); }; status = -1 ; goto BYE; }; }
    long long f1val = f1[f1idx];
    if ( f1val < minval ) { minval = f1val; }
    if ( f1val > maxval ) { maxval = f1val; }
    sum += (long long)f1val;
  }
  { if ( (status) < 0 ) { { { fprintf(stderr, "Line %3d of File %s \n", 43, "./AUX/pos_mmad_I8_I8.c"); }; status = (status) ; goto BYE; } } };
  *ptr_minval = minval;
  *ptr_maxval = maxval;
  *ptr_sum = sum;
BYE:
  return(status);
}

variable_types: status int

variable_types:
minval
long long

variable_types:
maxval
long long

variable_types:
sum
long long


repo: linux-sunxi/cedarx-libs

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

v3 = *(_QWORD *)(a2 + 24);
*(_QWORD *)(a3 + 16) = a2;
*(_QWORD *)(a3 + 24) = v3;
result = *(_QWORD *)(a2 + 24);
if ( result )
*(_QWORD *)(result + 16) = a3;
else
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a2 + 24) = a3;
return result;
}

original_code:
static void chunk_list_insert_after(chunk_list_t* list, chunk_t* chunk, chunk_t* new_chunk)
{
    new_chunk->prev = chunk;
    new_chunk->next = chunk->next;
    if(chunk->next == ((void *)0))
        list->last = new_chunk;
    else
        chunk->next->prev = new_chunk;
    chunk->next = new_chunk;
    return;
}

canonical_original_code:
static void chunk_list_insert_after(struct CHUNK_LIST *list, struct CHUNK *chunk, struct CHUNK *new_chunk)
{
    new_chunk->prev = chunk;
    new_chunk->next = chunk->next;
    if(chunk->next == ((void *)0))
        list->last = new_chunk;
    else
        chunk->next->prev = new_chunk;
    chunk->next = new_chunk;
    return;
}

variable_types: struct CHUNK_LIST { struct CHUNK { int page_offset; int page_num; int is_free; struct CHUNK *prev; struct CHUNK *next; } *first; struct CHUNK *last; } *

variable_types:
chunk
struct CHUNK *

user_defined_types: struct CHUNK_LIST { struct CHUNK *first; struct CHUNK *last; }


decompiled_code:
__int64 __fastcall chunk_list_remove(_QWORD *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
__int64 result; // rax

v2 = *(_QWORD *)(a2 + 16);
v3 = *(_QWORD *)(a2 + 24);
result = a2;
if ( v2 )
{
*(_QWORD *)(v2 + 24) = v3;
if ( v3 )
{
LABEL_3:
*(_QWORD *)(v3 + 16) = v2;
return result;
}
}
else
{
*a1 = v3;
if ( v3 )
goto LABEL_3;
}
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdx
__int64 result; // rax

v2 = *(_QWORD *)(a2 + 16);
v3 = *(_QWORD *)(a2 + 24);
result = a2;
if ( v2 )
{
*(_QWORD *)(v2 + 24) = v3;
if ( v3 )
{
LABEL_3:
*(_QWORD *)(v3 + 16) = v2;
return result;
}
}
else
{
*a1 = v3;
if ( v3 )
goto LABEL_3;
}
a1[1] = v2;
return result;
}

original_code:
static chunk_t* chunk_list_remove(chunk_list_t* list, chunk_t* chunk)
{
    if(chunk->prev == ((void *)0))
        list->first = chunk->next;
    else
        chunk->prev->next = chunk->next;
    if(chunk->next == ((void *)0))
        list->last = chunk->prev;
    else
        chunk->next->prev = chunk->prev;
    return chunk;
}

canonical_original_code:
static struct CHUNK *chunk_list_remove(struct CHUNK_LIST *list, struct CHUNK *chunk)
{
    if(chunk->prev == ((void *)0))
        list->first = chunk->next;
    else
        chunk->prev->next = chunk->next;
    if(chunk->next == ((void *)0))
        list->last = chunk->prev;
    else
        chunk->next->prev = chunk->prev;
    return chunk;
}

variable_types: struct CHUNK_LIST { struct CHUNK *first; struct CHUNK *last; } *

return_type: struct CHUNK { int page_offset; int page_num; int is_free; struct CHUNK *prev; struct CHUNK *next; } *


decompiled_code:
__int64 __fastcall av_heap_get_a_free_block(__int64 a1)
{
_DWORD *v1; // rdi
__int64 result; // rax

v1 = (_DWORD *)(a1 + 80);
result = 0LL;
while ( *v1 )
{
result = (unsigned int)(result + 1);
v1 += 6;
if ( (_DWORD)result == 1024 )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
_DWORD *v1; // rdi
__int64 result; // rax

v1 = (_DWORD *)(a1 + 80);
result = 0LL;
while ( *v1 )
{
result = (unsigned int)(result + 1);
v1 += 6;
if ( (_DWORD)result == 1024 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int av_heap_get_a_free_block(heap_ctx_t* ctx)
{
    int i;
    for(i=0; i<1024; i++)
    {
        if(ctx->block_info[i].is_used == 0)
            break;
    }
    if(i == 1024)
        return -1;
    else
        return i;
}

canonical_original_code:
static int av_heap_get_a_free_block(struct HEAP_CONTEXT *ctx)
{
    int i;
    for(i=0; i<1024; i++)
    {
        if(ctx->block_info[i].is_used == 0)
            break;
    }
    if(i == 1024)
        return -1;
    else
        return i;
}

variable_types: struct HEAP_CONTEXT { int fd; struct CEDARV_ENV_INFOMATION { unsigned int phymem_start; int phymem_total_size; unsigned int address_macc; } env_info; struct ALLOCATOR { struct CHUNK_LIST { struct CHUNK { int page_offset; int page_num; int is_free; struct CHUNK *prev; struct CHUNK *next; } *first; struct CHUNK *last; } *list; int heap_size; } *allocator; 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; } mutex; struct BLOCK_INFO { void *vaddr; void *paddr; int is_used; int size; } block_info[1024]; } *

variable_types: i int

user_defined_types: struct HEAP_CONTEXT { int fd; struct CEDARV_ENV_INFOMATION env_info; struct ALLOCATOR *allocator; union pthread_mutex_t mutex; struct BLOCK_INFO block_info[1024]; }

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

user_defined_types: struct ALLOCATOR { struct CHUNK_LIST *list; int heap_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; }


decompiled_code:
__int64 __fastcall av_heap_find_block_by_vaddr(__int64 a1, __int64 a2)
{
_QWORD *v2; // rdi
__int64 result; // rax

v2 = (_QWORD *)(a1 + 64);
result = 0LL;
while ( *v2 != a2 )
{
result = (unsigned int)(result + 1);
v2 += 3;
if ( (_DWORD)result == 1024 )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
_QWORD *v2; // rdi
__int64 result; // rax

v2 = (_QWORD *)(a1 + 64);
result = 0LL;
while ( *v2 != a2 )
{
result = (unsigned int)(result + 1);
v2 += 3;
if ( (_DWORD)result == 1024 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int av_heap_find_block_by_vaddr(heap_ctx_t* ctx, void* vaddr)
{
    int i;
    for(i=0; i<1024; i++)
    {
        if(ctx->block_info[i].vaddr == vaddr)
            break;
    }
    if(i == 1024)
        return -1;
    else
        return i;
}

canonical_original_code:
static int av_heap_find_block_by_vaddr(struct HEAP_CONTEXT *ctx, void *vaddr)
{
    int i;
    for(i=0; i<1024; i++)
    {
        if(ctx->block_info[i].vaddr == vaddr)
            break;
    }
    if(i == 1024)
        return -1;
    else
        return i;
}

variable_types:
vaddr
void *

user_defined_types: struct CEDARV_ENV_INFOMATION { unsigned int phymem_start; int phymem_total_size; unsigned int address_macc; }

user_defined_types: struct BLOCK_INFO { void *vaddr; void *paddr; int is_used; int size; }

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

user_defined_types: struct CHUNK { int page_offset; int page_num; int is_free; struct CHUNK *prev; struct CHUNK *next; }


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

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

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

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

original_code:
static chunk_list_t* chunk_list_create(void)
{
    chunk_list_t* list = (chunk_list_t*)malloc(sizeof(chunk_list_t));
    if(list != ((void *)0))
    {
        list->first = ((void *)0);
        list->last = ((void *)0);
    }
    return list;
}

canonical_original_code:
static struct CHUNK_LIST *chunk_list_create()
{
    struct CHUNK_LIST *list = (chunk_list_t*)malloc(sizeof(chunk_list_t));
    if(list != ((void *)0))
    {
        list->first = ((void *)0);
        list->last = ((void *)0);
    }
    return list;
}

return_type: struct CHUNK_LIST { struct CHUNK { int page_offset; int page_num; int is_free; struct CHUNK *prev; struct CHUNK *next; } *first; struct CHUNK *last; } *


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

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

original_code:
static void chunk_destroy(chunk_t* chunk)
{
    free(chunk);
    return;
}

canonical_original_code:
static void chunk_destroy(struct CHUNK *chunk)
{
    free(chunk);
    return;
}

variable_types: struct CHUNK { int page_offset; int page_num; int is_free; struct CHUNK *prev; struct CHUNK *next; } *


original_code:
static void allocator_free(allocator_t* allocator, int heap_offset)
{
    chunk_t* chunk_cur;
    chunk_t* chunk_prev;
    chunk_t* chunk_next;
    int page_offset;
    if(allocator == ((void *)0))
        return;
    page_offset = heap_offset / 4096;
    chunk_cur = chunk_list_head(allocator->list);
    while(chunk_cur != ((void *)0))
    {
        if(chunk_cur->page_offset == page_offset)
        {
            if(chunk_cur->is_free)
            {
                ;
            }
            chunk_cur->is_free = 1;
            do
            {
                chunk_prev = chunk_cur->prev;
                chunk_next = chunk_cur->next;
                if(chunk_prev != ((void *)0) && (chunk_prev->is_free == 1 || chunk_prev->page_num == 0))
                {
                    chunk_prev->page_num += chunk_cur->page_num;
                    chunk_list_remove(allocator->list, chunk_cur);
                    chunk_destroy(chunk_cur);
                }
                chunk_cur = chunk_next;
            }while(chunk_cur != ((void *)0) && chunk_cur->is_free == 1);
            break;
        }
        chunk_cur = chunk_cur->next;
    }
    return;
}

canonical_original_code:
static void allocator_free(struct ALLOCATOR *allocator, int heap_offset)
{
    struct CHUNK *chunk_cur;
    struct CHUNK *chunk_prev;
    struct CHUNK *chunk_next;
    int page_offset;
    if(allocator == ((void *)0))
        return;
    page_offset = heap_offset / 4096;
    chunk_cur = chunk_list_head(allocator->list);
    while(chunk_cur != ((void *)0))
    {
        if(chunk_cur->page_offset == page_offset)
        {
            if(chunk_cur->is_free)
            {
                ;
            }
            chunk_cur->is_free = 1;
            do
            {
                chunk_prev = chunk_cur->prev;
                chunk_next = chunk_cur->next;
                if(chunk_prev != ((void *)0) && (chunk_prev->is_free == 1 || chunk_prev->page_num == 0))
                {
                    chunk_prev->page_num += chunk_cur->page_num;
                    chunk_list_remove(allocator->list, chunk_cur);
                    chunk_destroy(chunk_cur);
                }
                chunk_cur = chunk_next;
            }while(chunk_cur != ((void *)0) && chunk_cur->is_free == 1);
            break;
        }
        chunk_cur = chunk_cur->next;
    }
    return;
}

variable_types: struct ALLOCATOR { struct CHUNK_LIST { struct CHUNK { int page_offset; int page_num; int is_free; struct CHUNK *prev; struct CHUNK *next; } *first; struct CHUNK *last; } *list; int heap_size; } *


decompiled_code:
__int64 __fastcall allocator_alloc(__int64 **a1, int a2)
{
__int64 v2; // rax
int v3; // ecx
_DWORD *v4; // rbx
int v5; // edx
__int64 result; // rax
int v7; // esi
_DWORD *v8; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
v2 = chunk_list_head_isra_0(**a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)(v2 + 8) )
{
v5 = *(_DWORD *)(v2 + 4);
if ( v5 >= v3 )
{
if ( v4 )
{
if ( v5 < v4[1] )
v4 = (_DWORD *)v2;
}
else
{
v4 = (_DWORD *)v2;
}
if ( v5 == v3 )
break;
}
}
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
{
result = 0xFFFFFFFFLL;
if ( !v4 )
return result;
break;
}
}
v7 = v4[1];
v4[2] = 0;
v4[1] = v3;
if ( v3 < v7 )
{
v8 = chunk_create(v3 + *v4, v7 - v3);
chunk_list_insert_after((__int64)*a1, (__int64)v4, (__int64)v8);
}
return (unsigned int)(*v4 << 12);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 **a1, int a2)
{
__int64 v2; // rax
int v3; // ecx
_DWORD *v4; // rbx
int v5; // edx
__int64 result; // rax
int v7; // esi
_DWORD *v8; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
v2 = func7(**a1);
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)(v2 + 8) )
{
v5 = *(_DWORD *)(v2 + 4);
if ( v5 >= v3 )
{
if ( v4 )
{
if ( v5 < v4[1] )
v4 = (_DWORD *)v2;
}
else
{
v4 = (_DWORD *)v2;
}
if ( v5 == v3 )
break;
}
}
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
{
result = 0xFFFFFFFFLL;
if ( !v4 )
return result;
break;
}
}
v7 = v4[1];
v4[2] = 0;
v4[1] = v3;
if ( v3 < v7 )
{
v8 = chunk_create(v3 + *v4, v7 - v3);
func0((__int64)*a1, (__int64)v4, (__int64)v8);
}
return (unsigned int)(*v4 << 12);
}

original_code:
static int allocator_alloc(allocator_t* allocator, int size)
{
    chunk_t* chunk_free;
    chunk_t* chunk_cur;
    chunk_t* chunk_split;
    int free_page_num;
    int page_num;
    int left_page_num;
    int heap_offset;
    if(size == 0)
        return -1;
    size = size + (4096 - 1);
    page_num = size / 4096;
    chunk_free = ((void *)0);
    chunk_cur = chunk_list_head(allocator->list);
    while(chunk_cur != ((void *)0))
    {
        if(chunk_cur->is_free && chunk_cur->page_num >= page_num)
        {
            if(chunk_free == ((void *)0) || chunk_cur->page_num < chunk_free->page_num)
                chunk_free = chunk_cur;
            if(chunk_cur->page_num == page_num)
                break;
        }
        chunk_cur = chunk_cur->next;
    }
    if(chunk_free != ((void *)0))
    {
        free_page_num = chunk_free->page_num;
        chunk_free->is_free = 0;
        chunk_free->page_num = page_num;
        if(free_page_num > page_num)
        {
            left_page_num = free_page_num - page_num;
            chunk_split = chunk_create(chunk_free->page_offset + page_num, left_page_num);
            chunk_list_insert_after(allocator->list, chunk_free, chunk_split);
        }
    }
    if(chunk_free != ((void *)0))
        heap_offset = chunk_free->page_offset * 4096;
    else
        heap_offset = -1;
    return heap_offset;
}

canonical_original_code:
static int allocator_alloc(struct ALLOCATOR *allocator, int size)
{
    struct CHUNK *chunk_free;
    struct CHUNK *chunk_cur;
    struct CHUNK *chunk_split;
    int free_page_num;
    int page_num;
    int left_page_num;
    int heap_offset;
    if(size == 0)
        return -1;
    size = size + (4096 - 1);
    page_num = size / 4096;
    chunk_free = ((void *)0);
    chunk_cur = chunk_list_head(allocator->list);
    while(chunk_cur != ((void *)0))
    {
        if(chunk_cur->is_free && chunk_cur->page_num >= page_num)
        {
            if(chunk_free == ((void *)0) || chunk_cur->page_num < chunk_free->page_num)
                chunk_free = chunk_cur;
            if(chunk_cur->page_num == page_num)
                break;
        }
        chunk_cur = chunk_cur->next;
    }
    if(chunk_free != ((void *)0))
    {
        free_page_num = chunk_free->page_num;
        chunk_free->is_free = 0;
        chunk_free->page_num = page_num;
        if(free_page_num > page_num)
        {
            left_page_num = free_page_num - page_num;
            chunk_split = chunk_create(chunk_free->page_offset + page_num, left_page_num);
            chunk_list_insert_after(allocator->list, chunk_free, chunk_split);
        }
    }
    if(chunk_free != ((void *)0))
        heap_offset = chunk_free->page_offset * 4096;
    else
        heap_offset = -1;
    return heap_offset;
}

variable_types: size int


decompiled_code:
void __fastcall chunk_list_destroy(void *ptr)
{
__int64 v2; // rax
void *v3; // rax
__int64 v4; // rdi

while ( 1 )
{
v4 = *(_QWORD *)ptr;
if ( !chunk_list_is_empty_isra_0(*(_QWORD *)ptr) )
break;
v2 = chunk_list_head_isra_0(v4);
v3 = (void *)chunk_list_remove(ptr, v2);
chunk_destroy(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
__int64 v2; // rax
void *v3; // rax
__int64 v4; // rdi

while ( 1 )
{
v4 = *(_QWORD *)ptr;
if ( !func10(*(_QWORD *)ptr) )
break;
v2 = func7(v4);
v3 = (void *)func2(ptr, v2);
func6(v3);
}
free(ptr);
}

original_code:
static void chunk_list_destroy(chunk_list_t* list)
{
    chunk_t* chunk;
    while(chunk_list_is_empty(list) == 1)
    {
        chunk = chunk_list_head(list);
        chunk = chunk_list_remove(list, chunk);
        chunk_destroy(chunk);
    }
    free(list);
}

canonical_original_code:
static void chunk_list_destroy(struct CHUNK_LIST *list)
{
    struct CHUNK *chunk;
    while(chunk_list_is_empty(list) == 1)
    {
        chunk = chunk_list_head(list);
        chunk = chunk_list_remove(list, chunk);
        chunk_destroy(chunk);
    }
    free(list);
}


decompiled_code:
void __fastcall allocator_destroy(void *ptr)
{
if ( ptr )
{
chunk_list_destroy(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
func11(*(void **)ptr);
free(ptr);
}
}

original_code:
static void allocator_destroy(allocator_t* allocator)
{
    if(allocator != ((void *)0))
    {
        chunk_list_destroy(allocator->list);
        free(allocator);
    }
    return;
}

canonical_original_code:
static void allocator_destroy(struct ALLOCATOR *allocator)
{
    if(allocator != ((void *)0))
    {
        chunk_list_destroy(allocator->list);
        free(allocator);
    }
    return;
}


decompiled_code:
__int64 __fastcall av_heap_init(int fd)
{
char *v1; // rax
int *v2; // rbp
pthread_mutex_t *v3; // r14
unsigned int v4; // er13
_DWORD *v5; // rax

if ( heap_ctx )
return (unsigned int)-1;
v1 = (char *)calloc(0x6040uLL, 1uLL);
heap_ctx = v1;
v2 = (int *)v1;
if ( !v1 )
return (unsigned int)-1;
v3 = (pthread_mutex_t *)(v1 + 24);
v4 = pthread_mutex_init((pthread_mutex_t *)(v1 + 24), 0LL);
if ( v4 )
{
LABEL_8:
free(v2);
heap_ctx = 0LL;
return (unsigned int)-1;
}
*v2 = fd;
if ( (unsigned int)(fd + 1) <= 1
|| (ioctl(fd, 0x101uLL, v2 + 1), v5 = allocator_create(v2[2]), (*((_QWORD *)v2 + 2) = v5) == 0LL) )
{
pthread_mutex_destroy(v3);
goto LABEL_8;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd)
{
char *v1; // rax
int *v2; // rbp
pthread_mutex_t *v3; // r14
unsigned int v4; // er13
_DWORD *v5; // rax

if ( heap_ctx )
return (unsigned int)-1;
v1 = (char *)calloc(0x6040uLL, 1uLL);
heap_ctx = v1;
v2 = (int *)v1;
if ( !v1 )
return (unsigned int)-1;
v3 = (pthread_mutex_t *)(v1 + 24);
v4 = pthread_mutex_init((pthread_mutex_t *)(v1 + 24), 0LL);
if ( v4 )
{
LABEL_8:
free(v2);
heap_ctx = 0LL;
return (unsigned int)-1;
}
*v2 = fd;
if ( (unsigned int)(fd + 1) <= 1
|| (ioctl(fd, 0x101uLL, v2 + 1), v5 = allocator_create(v2[2]), (*((_QWORD *)v2 + 2) = v5) == 0LL) )
{
pthread_mutex_destroy(v3);
goto LABEL_8;
}
return v4;
}

original_code:
int av_heap_init(int fd_ve)
{
    if(heap_ctx != ((void *)0))
    {
        ;
        return -1;
    }
    heap_ctx = (heap_ctx_t*)malloc(sizeof(heap_ctx_t));
    if(heap_ctx == ((void *)0))
    {
        ;
        return -1;
    }
    memset(heap_ctx, 0, sizeof(heap_ctx_t));
    if(pthread_mutex_init(&heap_ctx->mutex, ((void *)0)) != 0)
    {
        ;
        free(heap_ctx);
        heap_ctx = ((void *)0);
        return -1;
    }
    heap_ctx->fd = fd_ve;
    if(heap_ctx->fd == -1 || heap_ctx->fd == 0)
    {
        ;
        pthread_mutex_destroy(&heap_ctx->mutex);
        free(heap_ctx);
        heap_ctx = ((void *)0);
        return -1;
    }
    ioctl(heap_ctx->fd, IOCTL_GET_ENV_INFO, (unsigned int)&heap_ctx->env_info);
    heap_ctx->allocator = allocator_create(heap_ctx->env_info.phymem_total_size);
    if(heap_ctx->allocator == ((void *)0))
    {
        ;
        pthread_mutex_destroy(&heap_ctx->mutex);
        free(heap_ctx);
        heap_ctx = ((void *)0);
        return -1;
    }
    return 0;
}

canonical_original_code:
int av_heap_init(int fd_ve)
{
    if(heap_ctx != ((void *)0))
    {
        ;
        return -1;
    }
    heap_ctx = (struct HEAP_CONTEXT *)malloc(sizeof(heap_ctx_t));
    if(heap_ctx == ((void *)0))
    {
        ;
        return -1;
    }
    memset(heap_ctx, 0, sizeof(heap_ctx_t));
    if(pthread_mutex_init(&heap_ctx->mutex, ((void *)0)) != 0)
    {
        ;
        free(heap_ctx);
        heap_ctx = ((void *)0);
        return -1;
    }
    heap_ctx->fd = fd_ve;
    if(heap_ctx->fd == -1 || heap_ctx->fd == 0)
    {
        ;
        pthread_mutex_destroy(&heap_ctx->mutex);
        free(heap_ctx);
        heap_ctx = ((void *)0);
        return -1;
    }
    ioctl(heap_ctx->fd, IOCTL_GET_ENV_INFO, (unsigned int)&heap_ctx->env_info);
    heap_ctx->allocator = allocator_create(heap_ctx->env_info.phymem_total_size);
    if(heap_ctx->allocator == ((void *)0))
    {
        ;
        pthread_mutex_destroy(&heap_ctx->mutex);
        free(heap_ctx);
        heap_ctx = ((void *)0);
        return -1;
    }
    return 0;
}


decompiled_code:
void av_heap_release()
{
char *v0; // rbp
void *v1; // rdi

v0 = (char *)heap_ctx;
if ( heap_ctx )
{
v1 = (void *)*((_QWORD *)heap_ctx + 2);
if ( v1 )
allocator_destroy(v1);
pthread_mutex_destroy((pthread_mutex_t *)(v0 + 24));
free(v0);
heap_ctx = 0LL;
}
}

canonical_decompiled_code:
void func14()
{
char *v0; // rbp
void *v1; // rdi

v0 = (char *)heap_ctx;
if ( heap_ctx )
{
v1 = (void *)*((_QWORD *)heap_ctx + 2);
if ( v1 )
func12(v1);
pthread_mutex_destroy((pthread_mutex_t *)(v0 + 24));
free(v0);
heap_ctx = 0LL;
}
}

original_code:
void av_heap_release(void)
{
    if(heap_ctx == ((void *)0))
    {
        ;
        return;
    }
    if(heap_ctx->allocator != ((void *)0))
        allocator_destroy(heap_ctx->allocator);
    pthread_mutex_destroy(&heap_ctx->mutex);
    free(heap_ctx);
    heap_ctx = ((void *)0);
    return;
}

canonical_original_code:
void av_heap_release()
{
    if(heap_ctx == ((void *)0))
    {
        ;
        return;
    }
    if(heap_ctx->allocator != ((void *)0))
        allocator_destroy(heap_ctx->allocator);
    pthread_mutex_destroy(&heap_ctx->mutex);
    free(heap_ctx);
    heap_ctx = ((void *)0);
    return;
}


decompiled_code:
void *__fastcall av_heap_alloc(int a1)
{
void *result; // rax
char *v2; // rbx
int v3; // eax
int v4; // esi
pthread_mutex_t *v5; // r14
unsigned int v6; // er13
int v7; // eax
__int64 v8; // r12
void *v9; // rax
char *v10; // rbx

if ( a1 <= 0 )
return 0LL;
result = heap_ctx;
if ( heap_ctx )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)heap_ctx + 24));
v2 = (char *)heap_ctx;
v3 = allocator_alloc(*((__int64 ***)heap_ctx + 2), a1);
v4 = v3;
if ( v3 < 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 24));
result = 0LL;
}
else
{
v5 = (pthread_mutex_t *)(v2 + 24);
v6 = v3 + *((_DWORD *)v2 + 1);
v7 = av_heap_get_a_free_block((__int64)v2);
if ( v7 < 0 )
{
allocator_free(*((__int64 ***)v2 + 2), v4);
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 24));
result = 0LL;
}
else
{
v8 = 24LL * v7;
v9 = mmap(0LL, a1, 3, 1, *(_DWORD *)v2, v6);
v10 = &v2[v8];
*((_QWORD *)v10 + 8) = v9;
*((_QWORD *)v10 + 9) = v6 & 0x3FFFFFFF;
*((_DWORD *)v10 + 21) = a1;
*((_DWORD *)v10 + 20) = 1;
pthread_mutex_unlock(v5);
result = *(void **)((char *)heap_ctx + v8 + 64);
}
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func15(int a1)
{
void *result; // rax
char *v2; // rbx
int v3; // eax
int v4; // esi
pthread_mutex_t *v5; // r14
unsigned int v6; // er13
int v7; // eax
__int64 v8; // r12
void *v9; // rax
char *v10; // rbx

if ( a1 <= 0 )
return 0LL;
result = heap_ctx;
if ( heap_ctx )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)heap_ctx + 24));
v2 = (char *)heap_ctx;
v3 = func9(*((__int64 ***)heap_ctx + 2), a1);
v4 = v3;
if ( v3 < 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 24));
result = 0LL;
}
else
{
v5 = (pthread_mutex_t *)(v2 + 24);
v6 = v3 + *((_DWORD *)v2 + 1);
v7 = func3((__int64)v2);
if ( v7 < 0 )
{
func8(*((__int64 ***)v2 + 2), v4);
pthread_mutex_unlock((pthread_mutex_t *)(v2 + 24));
result = 0LL;
}
else
{
v8 = 24LL * v7;
v9 = mmap(0LL, a1, 3, 1, *(_DWORD *)v2, v6);
v10 = &v2[v8];
*((_QWORD *)v10 + 8) = v9;
*((_QWORD *)v10 + 9) = v6 & 0x3FFFFFFF;
*((_DWORD *)v10 + 21) = a1;
*((_DWORD *)v10 + 20) = 1;
pthread_mutex_unlock(v5);
result = *(void **)((char *)heap_ctx + v8 + 64);
}
}
}
return result;
}

original_code:
void* av_heap_alloc(int size)
{
    int offset;
    int block_idx;
    unsigned int paddr;
    if(size <= 0)
    {
        ;
        return ((void *)0);
    }
    if(heap_ctx == ((void *)0))
    {
        ;
        return ((void *)0);
    }
    pthread_mutex_lock(&heap_ctx->mutex);
    offset = allocator_alloc(heap_ctx->allocator, size);
    if(offset < 0)
    {
        ;
        pthread_mutex_unlock(&heap_ctx->mutex);
        return ((void *)0);
    }
    paddr = offset + heap_ctx->env_info.phymem_start;
    block_idx = av_heap_get_a_free_block(heap_ctx);
    if(block_idx < 0)
    {
        ;
        allocator_free(heap_ctx->allocator, offset);
        pthread_mutex_unlock(&heap_ctx->mutex);
        return ((void *)0);
    }
    heap_ctx->block_info[block_idx].vaddr = (void*)mmap(0, size, 0x1 | 0x2, 0x01, heap_ctx->fd, paddr);
    heap_ctx->block_info[block_idx].paddr = (void*)(paddr & 0x3fffffff);
    heap_ctx->block_info[block_idx].size = size;
    heap_ctx->block_info[block_idx].is_used = 1;
    pthread_mutex_unlock(&heap_ctx->mutex);
    return heap_ctx->block_info[block_idx].vaddr;
}

canonical_original_code:
void *av_heap_alloc(int size)
{
    int offset;
    int block_idx;
    unsigned int paddr;
    if(size <= 0)
    {
        ;
        return ((void *)0);
    }
    if(heap_ctx == ((void *)0))
    {
        ;
        return ((void *)0);
    }
    pthread_mutex_lock(&heap_ctx->mutex);
    offset = allocator_alloc(heap_ctx->allocator, size);
    if(offset < 0)
    {
        ;
        pthread_mutex_unlock(&heap_ctx->mutex);
        return ((void *)0);
    }
    paddr = offset + heap_ctx->env_info.phymem_start;
    block_idx = av_heap_get_a_free_block(heap_ctx);
    if(block_idx < 0)
    {
        ;
        allocator_free(heap_ctx->allocator, offset);
        pthread_mutex_unlock(&heap_ctx->mutex);
        return ((void *)0);
    }
    heap_ctx->block_info[block_idx].vaddr = (void *)mmap(0, size, 0x1 | 0x2, 0x01, heap_ctx->fd, paddr);
    heap_ctx->block_info[block_idx].paddr = (void *)(paddr & 0x3fffffff);
    heap_ctx->block_info[block_idx].size = size;
    heap_ctx->block_info[block_idx].is_used = 1;
    pthread_mutex_unlock(&heap_ctx->mutex);
    return heap_ctx->block_info[block_idx].vaddr;
}

variable_types: offset int

variable_types:
paddr
unsigned int

return_type: void *


decompiled_code:
void __fastcall av_heap_free(__int64 a1)
{
char *v1; // rbx
int v2; // eax
__int64 v3; // rbp
__int64 v4; // r12
__int64 v5; // rax

if ( heap_ctx )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)heap_ctx + 24));
v1 = (char *)heap_ctx;
v2 = av_heap_find_block_by_vaddr((__int64)heap_ctx, a1);
if ( v2 >= 0 )
{
v3 = 24LL * v2;
v4 = *(_QWORD *)&v1[v3 + 72] - (*((_DWORD *)v1 + 1) & 0x3FFFFFFF);
munmap(*(void **)&v1[v3 + 64], *(int *)&v1[v3 + 84]);
allocator_free(*((__int64 ***)v1 + 2), v4);
v5 = (__int64)&v1[v3 + 64];
*(_QWORD *)(v5 + 16) = 0LL;
*(_OWORD *)v5 = 0LL;
}
pthread_mutex_unlock((pthread_mutex_t *)(v1 + 24));
}
}

original_code:
void av_heap_free(void* vaddr)
{
    int block_idx;
    unsigned char* paddr;
    int offset;
    if(heap_ctx == ((void *)0))
    {
        ;
        return;
    }
    pthread_mutex_lock(&heap_ctx->mutex);
    block_idx = av_heap_find_block_by_vaddr(heap_ctx, vaddr);
    if(block_idx < 0)
    {
        ;
        pthread_mutex_unlock(&heap_ctx->mutex);
        return;
    }
    paddr = (unsigned char*)heap_ctx->block_info[block_idx].paddr;
    offset = (int)(paddr - (heap_ctx->env_info.phymem_start & 0x3fffffff));
    munmap(heap_ctx->block_info[block_idx].vaddr, heap_ctx->block_info[block_idx].size);
    allocator_free(heap_ctx->allocator, offset);
    memset(&heap_ctx->block_info[block_idx], 0, sizeof(block_info_t));
    pthread_mutex_unlock(&heap_ctx->mutex);
    return;
}

canonical_original_code:
void av_heap_free(void *vaddr)
{
    int block_idx;
    unsigned char *paddr;
    int offset;
    if(heap_ctx == ((void *)0))
    {
        ;
        return;
    }
    pthread_mutex_lock(&heap_ctx->mutex);
    block_idx = av_heap_find_block_by_vaddr(heap_ctx, vaddr);
    if(block_idx < 0)
    {
        ;
        pthread_mutex_unlock(&heap_ctx->mutex);
        return;
    }
    paddr = (unsigned char *)heap_ctx->block_info[block_idx].paddr;
    offset = (int)(paddr - (heap_ctx->env_info.phymem_start & 0x3fffffff));
    munmap(heap_ctx->block_info[block_idx].vaddr, heap_ctx->block_info[block_idx].size);
    allocator_free(heap_ctx->allocator, offset);
    memset(&heap_ctx->block_info[block_idx], 0, sizeof(block_info_t));
    pthread_mutex_unlock(&heap_ctx->mutex);
    return;
}

variable_types:
paddr
unsigned char *


decompiled_code:
__int64 __fastcall av_heap_physic_addr(__int64 a1)
{
int v1; // ebx
char *v2; // rax
int v3; // ebp

if ( a1 && heap_ctx )
{
v1 = 0;
pthread_mutex_lock((pthread_mutex_t *)((char *)heap_ctx + 24));
v2 = (char *)heap_ctx + 64;
do
{
if ( *((_DWORD *)v2 + 4) == 1 )
{
v3 = *(_QWORD *)v2;
if ( (unsigned int)a1 < v3 + *((_DWORD *)v2 + 5) && (unsigned int)a1 >= (unsigned int)*(_QWORD *)v2 )
{
pthread_mutex_unlock((pthread_mutex_t *)((char *)heap_ctx + 24));
return *((_QWORD *)heap_ctx + 3 * v1 + 9) + (unsigned int)(a1 - v3);
}
}
++v1;
v2 += 24;
}
while ( v1 != 1024 );
pthread_mutex_unlock((pthread_mutex_t *)((char *)heap_ctx + 24));
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
int v1; // ebx
char *v2; // rax
int v3; // ebp

if ( a1 && heap_ctx )
{
v1 = 0;
pthread_mutex_lock((pthread_mutex_t *)((char *)heap_ctx + 24));
v2 = (char *)heap_ctx + 64;
do
{
if ( *((_DWORD *)v2 + 4) == 1 )
{
v3 = *(_QWORD *)v2;
if ( (unsigned int)a1 < v3 + *((_DWORD *)v2 + 5) && (unsigned int)a1 >= (unsigned int)*(_QWORD *)v2 )
{
pthread_mutex_unlock((pthread_mutex_t *)((char *)heap_ctx + 24));
return *((_QWORD *)heap_ctx + 3 * v1 + 9) + (unsigned int)(a1 - v3);
}
}
++v1;
v2 += 24;
}
while ( v1 != 1024 );
pthread_mutex_unlock((pthread_mutex_t *)((char *)heap_ctx + 24));
}
return 0LL;
}

original_code:
void* av_heap_physic_addr(void* vaddr)
{
    int block_idx;
    unsigned int block_start;
    unsigned int block_end;
    unsigned int cur_addr;
    if(heap_ctx == ((void *)0))
    {
        ;
        return ((void *)0);
    }
    if(vaddr == ((void *)0))
        return ((void *)0);
    pthread_mutex_lock(&heap_ctx->mutex);
    cur_addr = (unsigned int)vaddr;
    for(block_idx = 0; block_idx < 1024; block_idx++)
    {
        if(heap_ctx->block_info[block_idx].is_used == 1)
        {
            block_start = (unsigned int)heap_ctx->block_info[block_idx].vaddr;
            block_end = block_start + heap_ctx->block_info[block_idx].size;
            if(block_start <= cur_addr && cur_addr < block_end)
                break;
        }
    }
    pthread_mutex_unlock(&heap_ctx->mutex);
    if(block_idx == 1024)
        return ((void *)0);
    return (unsigned char*)heap_ctx->block_info[block_idx].paddr + (cur_addr - block_start);
}

canonical_original_code:
void *av_heap_physic_addr(void *vaddr)
{
    int block_idx;
    unsigned int block_start;
    unsigned int block_end;
    unsigned int cur_addr;
    if(heap_ctx == ((void *)0))
    {
        ;
        return ((void *)0);
    }
    if(vaddr == ((void *)0))
        return ((void *)0);
    pthread_mutex_lock(&heap_ctx->mutex);
    cur_addr = (unsigned int)vaddr;
    for(block_idx = 0; block_idx < 1024; block_idx++)
    {
        if(heap_ctx->block_info[block_idx].is_used == 1)
        {
            block_start = (unsigned int)heap_ctx->block_info[block_idx].vaddr;
            block_end = block_start + heap_ctx->block_info[block_idx].size;
            if(block_start <= cur_addr && cur_addr < block_end)
                break;
        }
    }
    pthread_mutex_unlock(&heap_ctx->mutex);
    if(block_idx == 1024)
        return ((void *)0);
    return (unsigned char *)heap_ctx->block_info[block_idx].paddr + (cur_addr - block_start);
}


main

canonical_name: main

repo: nijel/weblate-hello

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

setlocale(6, "");
bindtextdomain("hello", "/usr/share/locale");
textdomain("hello");
v3 = dcgettext(0LL, "Hello, world!\n", 5);
printf(v3);
v4 = dcngettext(0LL, "Orangutan has %d banana.\n", "Orangutan has %d bananas.\n", 1uLL, 5);
printf(v4, 1LL);
v5 = dcgettext(0LL, "Try Weblate at <http://demo.weblate.org/>!\n", 5);
printf(v5);
v6 = dcgettext(0LL, "Thank you for using Weblate.", 5);
puts(v6);
exit(0);
}

original_code:
int main(void)
{
    int count = 1;
    setlocale( 6, "" );
    bindtextdomain( "hello", "/usr/share/locale" );
    textdomain( "hello" );
    printf( gettext( "Hello, world!\n" ) );
    printf( ngettext( "Orangutan has %d banana.\n", "Orangutan has %d bananas.\n", count ), count );
    printf( gettext( "Try Weblate at <http://demo.weblate.org/>!\n" ) );
    printf( "%s\n", gettext( "Thank you for using Weblate." ) );
    exit(0);
}

canonical_original_code:
int main()
{
    int count = 1;
    setlocale( 6, "" );
    bindtextdomain( "hello", "/usr/share/locale" );
    textdomain( "hello" );
    printf( gettext( "Hello, world!\n" ) );
    printf( ngettext( "Orangutan has %d banana.\n", "Orangutan has %d bananas.\n", count ), count );
    printf( gettext( "Try Weblate at <http://demo.weblate.org/>!\n" ) );
    printf( "%s\n", gettext( "Thank you for using Weblate." ) );
    exit(0);
}

variable_types: count int


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
struct dynarr *dynarr_new()
{
    struct dynarr *array = malloc(sizeof(struct dynarr));
    array->size = 0;
    array->alloc_size = 0;
    array->arr = 0;
    return array;
}

variable_types: struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *


decompiled_code:
void __fastcall dynarr_free(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

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

original_code:
void dynarr_free(struct dynarr *array)
{
    free(array->arr);
    free(array);
}

user_defined_types: struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; }


decompiled_code:
__int64 __fastcall dynarr_resize_down(__int64 a1, unsigned int a2)
{
unsigned int v3; // ecx
unsigned int v4; // eax
size_t v5; // rsi
unsigned int v6; // er12

v3 = *(_DWORD *)(a1 + 4);
if ( !v3 && a2 )
{
*(_DWORD *)(a1 + 4) = 1;
v5 = 1LL;
v6 = 1;
if ( a2 >= *(_DWORD *)a1 )
goto LABEL_11;
goto LABEL_9;
}
v4 = v3 >> 1;
if ( a2 >= v3 >> 1 )
{
if ( a2 >= *(_DWORD *)a1 )
return 0;
*(_DWORD *)a1 = a2;
v5 = v3;
LABEL_10:
v6 = v5 - v3;
if ( (_DWORD)v5 == v3 )
return v6;
goto LABEL_11;
}
do
{
v5 = v4;
v4 >>= 1;
}
while ( v4 > a2 );
*(_DWORD *)(a1 + 4) = v5;
if ( *(_DWORD *)a1 > a2 )
{
LABEL_9:
*(_DWORD *)a1 = a2;
goto LABEL_10;
}
v6 = v5 - v3;
if ( (_DWORD)v5 == v3 )
return v6;
LABEL_11:
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
unsigned int v3; // ecx
unsigned int v4; // eax
size_t v5; // rsi
unsigned int v6; // er12

v3 = *(_DWORD *)(a1 + 4);
if ( !v3 && a2 )
{
*(_DWORD *)(a1 + 4) = 1;
v5 = 1LL;
v6 = 1;
if ( a2 >= *(_DWORD *)a1 )
goto LABEL_11;
goto LABEL_9;
}
v4 = v3 >> 1;
if ( a2 >= v3 >> 1 )
{
if ( a2 >= *(_DWORD *)a1 )
return 0;
*(_DWORD *)a1 = a2;
v5 = v3;
LABEL_10:
v6 = v5 - v3;
if ( (_DWORD)v5 == v3 )
return v6;
goto LABEL_11;
}
do
{
v5 = v4;
v4 >>= 1;
}
while ( v4 > a2 );
*(_DWORD *)(a1 + 4) = v5;
if ( *(_DWORD *)a1 > a2 )
{
LABEL_9:
*(_DWORD *)a1 = a2;
goto LABEL_10;
}
v6 = v5 - v3;
if ( (_DWORD)v5 == v3 )
return v6;
LABEL_11:
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v5);
return v6;
}

original_code:
int dynarr_resize_down(struct dynarr *array, unsigned int size)
{
    int old_size = array->alloc_size;
    if (size && !array->alloc_size)
        array->alloc_size = 1;
    while (size < array->alloc_size / 2)
        array->alloc_size = array->alloc_size / 2;
    if (array->size > size)
        array->size = size;
    int diff = array->alloc_size - old_size;
    if (diff)
        array->arr = (dynarr_info_t *) realloc(array->arr, array->alloc_size * sizeof(dynarr_info_t));
    return diff;
}

canonical_original_code:
int dynarr_resize_down(struct dynarr *array, unsigned int size)
{
    int old_size = array->alloc_size;
    if (size && !array->alloc_size)
        array->alloc_size = 1;
    while (size < array->alloc_size / 2)
        array->alloc_size = array->alloc_size / 2;
    if (array->size > size)
        array->size = size;
    int diff = array->alloc_size - old_size;
    if (diff)
        array->arr = (char *) realloc(array->arr, array->alloc_size * sizeof(dynarr_info_t));
    return diff;
}

variable_types:
size
unsigned int

variable_types: diff int


decompiled_code:
__int64 __fastcall dynarr_remove(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi
int v4; // esi
unsigned int v5; // esi

v3 = a2;
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 <= (unsigned int)v3 )
return 0LL;
if ( v4 + ~(_DWORD)v3 )
{
memmove((void *)(*(_QWORD *)(a1 + 8) + v3), (const void *)(*(_QWORD *)(a1 + 8) + v3 + 1), v4 + ~(_DWORD)v3);
v5 = *(_DWORD *)a1 - 1;
}
else
{
v5 = v4 - 1;
}
*(_DWORD *)a1 = v5;
return dynarr_resize_down(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 v3; // rdi
int v4; // esi
unsigned int v5; // esi

v3 = a2;
v4 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 <= (unsigned int)v3 )
return 0LL;
if ( v4 + ~(_DWORD)v3 )
{
memmove((void *)(*(_QWORD *)(a1 + 8) + v3), (const void *)(*(_QWORD *)(a1 + 8) + v3 + 1), v4 + ~(_DWORD)v3);
v5 = *(_DWORD *)a1 - 1;
}
else
{
v5 = v4 - 1;
}
*(_DWORD *)a1 = v5;
return func2(a1, v5);
}

original_code:
int dynarr_remove(struct dynarr *array, unsigned int pos)
{
    if (pos >= array->size)
        return 0;
    int rest = array->size - pos - 1;
    if (rest)
        memmove(array->arr + pos, array->arr + pos + 1, rest * sizeof(dynarr_info_t));
    return dynarr_resize_down(array, --array->size);
}

variable_types:
pos
unsigned int

variable_types: rest int