decompiled_code:
__int64 __fastcall dcm_open(int a1, int a2)
{
__int64 v3; // r9
__int64 v4; // r10
unsigned int v5; // edx
int *v6; // rsi
unsigned int v7; // edi
__int64 v8; // rcx
__int64 v9; // rsi
int *v10; // rsi
__int64 result; // rax
__int64 v12; // rdx
int v13; // ecx
int *v14; // rsi
__int64 v15; // rax
__int64 v16; // rsi
__int64 v17; // rsi
int v18; // eax
unsigned int v19; // ebx
__int64 v20; // rsi
unsigned __int64 v21; // rax

v3 = 1246751953 * a1 % 0x3D090u;
v4 = (unsigned int)dcm_inodehash[v3];
if ( (unsigned int)v4 > (unsigned int)&unk_7A11F )
{
LABEL_13:
v12 = (unsigned int)dcm_lru_first;
v13 = dcm_lru_first;
v14 = &dcm_tab[6 * dcm_lru_first];
v15 = (unsigned int)v14[4];
v16 = (unsigned int)v14[5];
if ( (unsigned int)v15 <= (unsigned int)&unk_7A11F )
dword_F4894[6 * (unsigned int)v15] = v16;
else
dcm_lru_first = v16;
if ( (unsigned int)v16 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v16] = v15;
v15 = (unsigned int)dcm_lru_last;
}
dcm_lru_last = v13;
v17 = 6 * v12;
dword_F4890[v17] = v15;
dword_F4894[v17] = -1;
dword_F4894[6 * v15] = v13;
v18 = dcm_tab[6 * v12];
if ( v18 )
{
v19 = HIDWORD(qword_F4884[3 * v12]);
v20 = (unsigned int)dword_F488C[6 * v12];
if ( v19 <= (unsigned int)&unk_7A11F )
{
dword_F488C[6 * v19] = v20;
}
else
{
dcm_inodehash[1246751953 * v18 % 0x3D090u] = v20;
v4 = (unsigned int)dcm_inodehash[v3];
}
if ( (unsigned int)v20 <= (unsigned int)&unk_7A11F )
HIDWORD(qword_F4884[3 * v20]) = v19;
}
dcm_inodehash[v3] = v13;
v21 = 24 * v12;
dcm_tab[v21 / 4] = a1;
dword_F488C[v21 / 4] = v4;
qword_F4884[v21 / 8] = (2LL * (a2 & 0x7FFFFFFF)) | 0xFFFFFFFF00000000LL;
result = 0LL;
if ( (unsigned int)v4 <= (unsigned int)&unk_7A11F )
HIDWORD(qword_F4884[3 * v4]) = v13;
}
else
{
v5 = dcm_inodehash[v3];
while ( 1 )
{
v6 = &dcm_tab[6 * v5];
if ( *v6 == a1 && (unsigned int)v6[1] >> 1 == a2 )
break;
v5 = dword_F488C[6 * v5];
if ( v5 > (unsigned int)&unk_7A11F )
goto LABEL_13;
}
v7 = dcm_lru_last;
if ( dcm_lru_last != v5 )
{
v8 = (unsigned int)v6[4];
v9 = (unsigned int)v6[5];
if ( (unsigned int)v8 > (unsigned int)&unk_7A11F )
dcm_lru_first = v9;
else
dword_F4894[6 * (unsigned int)v8] = v9;
if ( (unsigned int)v9 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v9] = v8;
v8 = v7;
}
dcm_lru_last = v5;
v10 = &dcm_tab[6 * v5];
v10[4] = v8;
v10[5] = -1;
dword_F4894[6 * v8] = v5;
}
result = qword_F4884[3 * v5] & 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 v3; // r9
__int64 v4; // r10
unsigned int v5; // edx
int *v6; // rsi
unsigned int v7; // edi
__int64 v8; // rcx
__int64 v9; // rsi
int *v10; // rsi
__int64 result; // rax
__int64 v12; // rdx
int v13; // ecx
int *v14; // rsi
__int64 v15; // rax
__int64 v16; // rsi
__int64 v17; // rsi
int v18; // eax
unsigned int v19; // ebx
__int64 v20; // rsi
unsigned __int64 v21; // rax

v3 = 1246751953 * a1 % 0x3D090u;
v4 = (unsigned int)dcm_inodehash[v3];
if ( (unsigned int)v4 > (unsigned int)&unk_7A11F )
{
LABEL_13:
v12 = (unsigned int)dcm_lru_first;
v13 = dcm_lru_first;
v14 = &dcm_tab[6 * dcm_lru_first];
v15 = (unsigned int)v14[4];
v16 = (unsigned int)v14[5];
if ( (unsigned int)v15 <= (unsigned int)&unk_7A11F )
dword_F4894[6 * (unsigned int)v15] = v16;
else
dcm_lru_first = v16;
if ( (unsigned int)v16 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v16] = v15;
v15 = (unsigned int)dcm_lru_last;
}
dcm_lru_last = v13;
v17 = 6 * v12;
dword_F4890[v17] = v15;
dword_F4894[v17] = -1;
dword_F4894[6 * v15] = v13;
v18 = dcm_tab[6 * v12];
if ( v18 )
{
v19 = HIDWORD(qword_F4884[3 * v12]);
v20 = (unsigned int)dword_F488C[6 * v12];
if ( v19 <= (unsigned int)&unk_7A11F )
{
dword_F488C[6 * v19] = v20;
}
else
{
dcm_inodehash[1246751953 * v18 % 0x3D090u] = v20;
v4 = (unsigned int)dcm_inodehash[v3];
}
if ( (unsigned int)v20 <= (unsigned int)&unk_7A11F )
HIDWORD(qword_F4884[3 * v20]) = v19;
}
dcm_inodehash[v3] = v13;
v21 = 24 * v12;
dcm_tab[v21 / 4] = a1;
dword_F488C[v21 / 4] = v4;
qword_F4884[v21 / 8] = (2LL * (a2 & 0x7FFFFFFF)) | 0xFFFFFFFF00000000LL;
result = 0LL;
if ( (unsigned int)v4 <= (unsigned int)&unk_7A11F )
HIDWORD(qword_F4884[3 * v4]) = v13;
}
else
{
v5 = dcm_inodehash[v3];
while ( 1 )
{
v6 = &dcm_tab[6 * v5];
if ( *v6 == a1 && (unsigned int)v6[1] >> 1 == a2 )
break;
v5 = dword_F488C[6 * v5];
if ( v5 > (unsigned int)&unk_7A11F )
goto LABEL_13;
}
v7 = dcm_lru_last;
if ( dcm_lru_last != v5 )
{
v8 = (unsigned int)v6[4];
v9 = (unsigned int)v6[5];
if ( (unsigned int)v8 > (unsigned int)&unk_7A11F )
dcm_lru_first = v9;
else
dword_F4894[6 * (unsigned int)v8] = v9;
if ( (unsigned int)v9 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v9] = v8;
v8 = v7;
}
dcm_lru_last = v5;
v10 = &dcm_tab[6 * v5];
v10[4] = v8;
v10[5] = -1;
dword_F4894[6 * v8] = v5;
}
result = qword_F4884[3 * v5] & 1;
}
return result;
}

original_code:
int dcm_open(uint32_t inode,uint32_t sessionid) {
 uint32_t ih = (((inode)*0x4A4FECD1)%((500000)/2));
 uint32_t p,pp,np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   return dcm_tab[p].cacheok;
  }
  p = dcm_tab[p].inext;
 }
 p = dcm_lru_first;
 pp = dcm_tab[p].lruprev;
 np = dcm_tab[p].lrunext;
 if (pp<500000) {
  dcm_tab[pp].lrunext = np;
 } else {
  dcm_lru_first = np;
 }
 if (np<500000) {
  dcm_tab[np].lruprev = pp;
 } else {
  dcm_lru_last = pp;
 }
 dcm_tab[p].lruprev = dcm_lru_last;
 dcm_tab[p].lrunext = 0xFFFFFFFF;
 dcm_tab[dcm_lru_last].lrunext = p;
 dcm_lru_last = p;
 if (dcm_tab[p].inode>0) {
  ih = (((dcm_tab[p].inode)*0x4A4FECD1)%((500000)/2));
  pp = dcm_tab[p].iprev;
  np = dcm_tab[p].inext;
  if (pp<500000) {
   dcm_tab[pp].inext = np;
  } else {
   dcm_inodehash[ih] = np;
  }
  if (np<500000) {
   dcm_tab[np].iprev = pp;
  }
 }
 dcm_tab[p].inode = inode;
 dcm_tab[p].cacheok = 0;
 dcm_tab[p].sessionid = sessionid;
 ih = (((inode)*0x4A4FECD1)%((500000)/2));
 np = dcm_inodehash[ih];
 dcm_tab[p].inext = np;
 dcm_tab[p].iprev = 0xFFFFFFFF;
 dcm_inodehash[ih] = p;
 if (np<500000) {
  dcm_tab[np].iprev = p;
 }
 return 0;
}

canonical_original_code:
int dcm_open(unsigned int inode, unsigned int sessionid) {
 unsigned int ih = (((inode)*0x4A4FECD1)%((500000)/2));
 unsigned int p; unsigned int pp; unsigned int np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   return dcm_tab[p].cacheok;
  }
  p = dcm_tab[p].inext;
 }
 p = dcm_lru_first;
 pp = dcm_tab[p].lruprev;
 np = dcm_tab[p].lrunext;
 if (pp<500000) {
  dcm_tab[pp].lrunext = np;
 } else {
  dcm_lru_first = np;
 }
 if (np<500000) {
  dcm_tab[np].lruprev = pp;
 } else {
  dcm_lru_last = pp;
 }
 dcm_tab[p].lruprev = dcm_lru_last;
 dcm_tab[p].lrunext = 0xFFFFFFFF;
 dcm_tab[dcm_lru_last].lrunext = p;
 dcm_lru_last = p;
 if (dcm_tab[p].inode>0) {
  ih = (((dcm_tab[p].inode)*0x4A4FECD1)%((500000)/2));
  pp = dcm_tab[p].iprev;
  np = dcm_tab[p].inext;
  if (pp<500000) {
   dcm_tab[pp].inext = np;
  } else {
   dcm_inodehash[ih] = np;
  }
  if (np<500000) {
   dcm_tab[np].iprev = pp;
  }
 }
 dcm_tab[p].inode = inode;
 dcm_tab[p].cacheok = 0;
 dcm_tab[p].sessionid = sessionid;
 ih = (((inode)*0x4A4FECD1)%((500000)/2));
 np = dcm_inodehash[ih];
 dcm_tab[p].inext = np;
 dcm_tab[p].iprev = 0xFFFFFFFF;
 dcm_inodehash[ih] = p;
 if (np<500000) {
  dcm_tab[np].iprev = p;
 }
 return 0;
}

variable_types:
inode
unsigned int

variable_types:
sessionid
unsigned int

variable_types:
ih
unsigned int

variable_types:
p
unsigned int

variable_types:
pp
unsigned int

variable_types:
np
unsigned int


repo: twonly/mfs

decompiled_code:
__int64 __fastcall dcm_access(int a1, int a2)
{
__int64 result; // rax
unsigned int v4; // edx
int *v5; // rsi
unsigned int v6; // edi
__int64 v7; // rcx
__int64 v8; // rsi
int *v9; // rsi

result = 250000 * (1246751953 * a1 / 0x3D090u);
v4 = dcm_inodehash[1246751953 * a1 % 0x3D090u];
if ( v4 <= (unsigned int)&unk_7A11F )
{
while ( 1 )
{
v5 = &dcm_tab[6 * v4];
if ( *v5 == a1 && (unsigned int)v5[1] >> 1 == a2 )
break;
result = 3LL * v4;
v4 = dword_F488C[6 * v4];
if ( v4 > (unsigned int)&unk_7A11F )
return result;
}
v6 = dcm_lru_last;
if ( dcm_lru_last != v4 )
{
v7 = (unsigned int)v5[4];
v8 = (unsigned int)v5[5];
if ( (unsigned int)v7 > (unsigned int)&unk_7A11F )
dcm_lru_first = v8;
else
dword_F4894[6 * (unsigned int)v7] = v8;
if ( (unsigned int)v8 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v8] = v7;
v7 = v6;
}
dcm_lru_last = v4;
v9 = &dcm_tab[6 * v4];
v9[4] = v7;
v9[5] = -1;
dword_F4894[6 * v7] = v4;
}
result = 3LL * v4;
LOBYTE(qword_F4884[3 * v4]) |= 1u;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 result; // rax
unsigned int v4; // edx
int *v5; // rsi
unsigned int v6; // edi
__int64 v7; // rcx
__int64 v8; // rsi
int *v9; // rsi

result = 250000 * (1246751953 * a1 / 0x3D090u);
v4 = dcm_inodehash[1246751953 * a1 % 0x3D090u];
if ( v4 <= (unsigned int)&unk_7A11F )
{
while ( 1 )
{
v5 = &dcm_tab[6 * v4];
if ( *v5 == a1 && (unsigned int)v5[1] >> 1 == a2 )
break;
result = 3LL * v4;
v4 = dword_F488C[6 * v4];
if ( v4 > (unsigned int)&unk_7A11F )
return result;
}
v6 = dcm_lru_last;
if ( dcm_lru_last != v4 )
{
v7 = (unsigned int)v5[4];
v8 = (unsigned int)v5[5];
if ( (unsigned int)v7 > (unsigned int)&unk_7A11F )
dcm_lru_first = v8;
else
dword_F4894[6 * (unsigned int)v7] = v8;
if ( (unsigned int)v8 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v8] = v7;
v7 = v6;
}
dcm_lru_last = v4;
v9 = &dcm_tab[6 * v4];
v9[4] = v7;
v9[5] = -1;
dword_F4894[6 * v7] = v4;
}
result = 3LL * v4;
LOBYTE(qword_F4884[3 * v4]) |= 1u;
}
return result;
}

original_code:
void dcm_access(uint32_t inode,uint32_t sessionid) {
 uint32_t ih = (((inode)*0x4A4FECD1)%((500000)/2));
 uint32_t p,pp,np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   dcm_tab[p].cacheok = 1;
   return;
  }
  p = dcm_tab[p].inext;
 }
}

canonical_original_code:
void dcm_access(unsigned int inode, unsigned int sessionid) {
 unsigned int ih = (((inode)*0x4A4FECD1)%((500000)/2));
 unsigned int p; unsigned int pp; unsigned int np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
   if (dcm_lru_last!=p) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = dcm_lru_last;
    dcm_tab[p].lrunext = 0xFFFFFFFF;
    dcm_tab[dcm_lru_last].lrunext = p;
    dcm_lru_last = p;
   }
   dcm_tab[p].cacheok = 1;
   return;
  }
  p = dcm_tab[p].inext;
 }
}

return_type: void


decompiled_code:
__int64 __fastcall dcm_modify(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // r10
unsigned int v4; // edx
unsigned int v5; // er11
char v7; // bp
__int64 v8; // r8
char v9; // bl
int *v10; // rsi
unsigned int v11; // ebp
__int64 v12; // rcx
int *v13; // rcx
int *v14; // rcx
unsigned int v15; // esi
unsigned int v16; // ecx
__int64 v17; // rcx
__int64 v18; // rsi
int *v19; // rsi

result = 250000 * (1246751953 * a1 / 0x3D090u);
v3 = 1246751953 * a1 % 0x3D090u;
v4 = dcm_inodehash[v3];
if ( v4 > (unsigned int)&unk_7A11F )
return result;
v5 = dcm_lru_last;
v7 = 0;
v8 = (unsigned int)dcm_lru_first;
v9 = 0;
do
{
while ( 1 )
{
v10 = &dcm_tab[6 * v4];
if ( *v10 == a1 )
break;
LABEL_3:
result = 3LL * v4;
v4 = dword_F488C[6 * v4];
if ( v4 > (unsigned int)&unk_7A11F )
goto LABEL_17;
}
if ( (unsigned int)v10[1] >> 1 == a2 )
{
if ( v5 != v4 )
{
v17 = (unsigned int)v10[4];
v18 = (unsigned int)v10[5];
if ( (unsigned int)v17 <= (unsigned int)&unk_7A11F )
{
dword_F4894[6 * (unsigned int)v17] = v18;
}
else
{
v8 = (unsigned int)v18;
v7 = 1;
}
if ( (unsigned int)v18 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v18] = v17;
v17 = v5;
}
v9 = 1;
v19 = &dcm_tab[6 * v4];
v19[4] = v17;
v19[5] = -1;
dword_F4894[6 * v17] = v4;
}
v5 = v4;
LOBYTE(qword_F4884[3 * v4]) |= 1u;
goto LABEL_3;
}
if ( (_DWORD)v8 != v4 )
{
v11 = v10[4];
v12 = (unsigned int)v10[5];
if ( v11 > (unsigned int)&unk_7A11F )
v8 = (unsigned int)v12;
else
dword_F4894[6 * v11] = v12;
if ( (unsigned int)v12 > (unsigned int)&unk_7A11F )
{
v5 = v11;
v9 = 1;
}
else
{
dword_F4890[6 * v12] = v11;
}
v7 = 1;
v13 = &dcm_tab[6 * v4];
v13[4] = -1;
v13[5] = v8;
dword_F4890[6 * v8] = v4;
}
v14 = &dcm_tab[6 * v4];
v15 = v14[2];
v16 = v14[3];
if ( v15 > (unsigned int)&unk_7A11F )
dcm_inodehash[v3] = v16;
else
dword_F488C[6 * v15] = v16;
if ( v16 <= (unsigned int)&unk_7A11F )
HIDWORD(qword_F4884[3 * v16]) = v15;
result = 3LL * v4;
v8 = v4;
v4 = v16;
dcm_tab[2 * result] = 0;
*(__int64 *)((char *)&qword_F4884[result] + 4) = -1LL;
}
while ( v16 <= (unsigned int)&unk_7A11F );
LABEL_17:
if ( v7 )
dcm_lru_first = v8;
if ( v9 )
dcm_lru_last = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // r10
unsigned int v4; // edx
unsigned int v5; // er11
char v7; // bp
__int64 v8; // r8
char v9; // bl
int *v10; // rsi
unsigned int v11; // ebp
__int64 v12; // rcx
int *v13; // rcx
int *v14; // rcx
unsigned int v15; // esi
unsigned int v16; // ecx
__int64 v17; // rcx
__int64 v18; // rsi
int *v19; // rsi

result = 250000 * (1246751953 * a1 / 0x3D090u);
v3 = 1246751953 * a1 % 0x3D090u;
v4 = dcm_inodehash[v3];
if ( v4 > (unsigned int)&unk_7A11F )
return result;
v5 = dcm_lru_last;
v7 = 0;
v8 = (unsigned int)dcm_lru_first;
v9 = 0;
do
{
while ( 1 )
{
v10 = &dcm_tab[6 * v4];
if ( *v10 == a1 )
break;
LABEL_3:
result = 3LL * v4;
v4 = dword_F488C[6 * v4];
if ( v4 > (unsigned int)&unk_7A11F )
goto LABEL_17;
}
if ( (unsigned int)v10[1] >> 1 == a2 )
{
if ( v5 != v4 )
{
v17 = (unsigned int)v10[4];
v18 = (unsigned int)v10[5];
if ( (unsigned int)v17 <= (unsigned int)&unk_7A11F )
{
dword_F4894[6 * (unsigned int)v17] = v18;
}
else
{
v8 = (unsigned int)v18;
v7 = 1;
}
if ( (unsigned int)v18 <= (unsigned int)&unk_7A11F )
{
dword_F4890[6 * v18] = v17;
v17 = v5;
}
v9 = 1;
v19 = &dcm_tab[6 * v4];
v19[4] = v17;
v19[5] = -1;
dword_F4894[6 * v17] = v4;
}
v5 = v4;
LOBYTE(qword_F4884[3 * v4]) |= 1u;
goto LABEL_3;
}
if ( (_DWORD)v8 != v4 )
{
v11 = v10[4];
v12 = (unsigned int)v10[5];
if ( v11 > (unsigned int)&unk_7A11F )
v8 = (unsigned int)v12;
else
dword_F4894[6 * v11] = v12;
if ( (unsigned int)v12 > (unsigned int)&unk_7A11F )
{
v5 = v11;
v9 = 1;
}
else
{
dword_F4890[6 * v12] = v11;
}
v7 = 1;
v13 = &dcm_tab[6 * v4];
v13[4] = -1;
v13[5] = v8;
dword_F4890[6 * v8] = v4;
}
v14 = &dcm_tab[6 * v4];
v15 = v14[2];
v16 = v14[3];
if ( v15 > (unsigned int)&unk_7A11F )
dcm_inodehash[v3] = v16;
else
dword_F488C[6 * v15] = v16;
if ( v16 <= (unsigned int)&unk_7A11F )
HIDWORD(qword_F4884[3 * v16]) = v15;
result = 3LL * v4;
v8 = v4;
v4 = v16;
dcm_tab[2 * result] = 0;
*(__int64 *)((char *)&qword_F4884[result] + 4) = -1LL;
}
while ( v16 <= (unsigned int)&unk_7A11F );
LABEL_17:
if ( v7 )
dcm_lru_first = v8;
if ( v9 )
dcm_lru_last = v5;
return result;
}

original_code:
void dcm_modify(uint32_t inode,uint32_t sessionid) {
 uint32_t ih = (((inode)*0x4A4FECD1)%((500000)/2));
 uint32_t p,pp,np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid != sessionid) {
   if (p!=dcm_lru_first) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = 0xFFFFFFFF;
    dcm_tab[p].lrunext = dcm_lru_first;
    dcm_tab[dcm_lru_first].lruprev = p;
    dcm_lru_first = p;
   }
   pp = dcm_tab[p].iprev;
   np = dcm_tab[p].inext;
   if (pp<500000) {
    dcm_tab[pp].inext = np;
   } else {
    dcm_inodehash[ih] = np;
   }
   if (np<500000) {
    dcm_tab[np].iprev = pp;
   }
   dcm_tab[p].inode = 0;
   dcm_tab[p].inext = 0xFFFFFFFF;
   dcm_tab[p].iprev = 0xFFFFFFFF;
   p = np;
  } else {
   if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
    if (dcm_lru_last!=p) {
     pp = dcm_tab[p].lruprev;
     np = dcm_tab[p].lrunext;
     if (pp<500000) {
      dcm_tab[pp].lrunext = np;
     } else {
      dcm_lru_first = np;
     }
     if (np<500000) {
      dcm_tab[np].lruprev = pp;
     } else {
      dcm_lru_last = pp;
     }
     dcm_tab[p].lruprev = dcm_lru_last;
     dcm_tab[p].lrunext = 0xFFFFFFFF;
     dcm_tab[dcm_lru_last].lrunext = p;
     dcm_lru_last = p;
    }
    dcm_tab[p].cacheok = 1;
   }
   p = dcm_tab[p].inext;
  }
 }
}

canonical_original_code:
void dcm_modify(unsigned int inode, unsigned int sessionid) {
 unsigned int ih = (((inode)*0x4A4FECD1)%((500000)/2));
 unsigned int p; unsigned int pp; unsigned int np;
 p = dcm_inodehash[ih];
 while (p<500000) {
  if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid != sessionid) {
   if (p!=dcm_lru_first) {
    pp = dcm_tab[p].lruprev;
    np = dcm_tab[p].lrunext;
    if (pp<500000) {
     dcm_tab[pp].lrunext = np;
    } else {
     dcm_lru_first = np;
    }
    if (np<500000) {
     dcm_tab[np].lruprev = pp;
    } else {
     dcm_lru_last = pp;
    }
    dcm_tab[p].lruprev = 0xFFFFFFFF;
    dcm_tab[p].lrunext = dcm_lru_first;
    dcm_tab[dcm_lru_first].lruprev = p;
    dcm_lru_first = p;
   }
   pp = dcm_tab[p].iprev;
   np = dcm_tab[p].inext;
   if (pp<500000) {
    dcm_tab[pp].inext = np;
   } else {
    dcm_inodehash[ih] = np;
   }
   if (np<500000) {
    dcm_tab[np].iprev = pp;
   }
   dcm_tab[p].inode = 0;
   dcm_tab[p].inext = 0xFFFFFFFF;
   dcm_tab[p].iprev = 0xFFFFFFFF;
   p = np;
  } else {
   if (dcm_tab[p].inode == inode && dcm_tab[p].sessionid == sessionid) {
    if (dcm_lru_last!=p) {
     pp = dcm_tab[p].lruprev;
     np = dcm_tab[p].lrunext;
     if (pp<500000) {
      dcm_tab[pp].lrunext = np;
     } else {
      dcm_lru_first = np;
     }
     if (np<500000) {
      dcm_tab[np].lruprev = pp;
     } else {
      dcm_lru_last = pp;
     }
     dcm_tab[p].lruprev = dcm_lru_last;
     dcm_tab[p].lrunext = 0xFFFFFFFF;
     dcm_tab[dcm_lru_last].lrunext = p;
     dcm_lru_last = p;
    }
    dcm_tab[p].cacheok = 1;
   }
   p = dcm_tab[p].inext;
  }
 }
}


decompiled_code:
__int64 dcm_init()
{
int *v0; // rax
unsigned int v1; // edx
int v2; // ecx
__int64 result; // rax

memset(dcm_inodehash, 255, (size_t)&unk_F4240);
v0 = dcm_tab;
v1 = 0;
do
{
*v0 = 0;
v0 += 6;
LODWORD(qword_F4884[3 * v1]) &= 1u;
v2 = v1++ - 1;
*(v0 - 4) = -1;
*(v0 - 3) = -1;
*(v0 - 2) = v2;
*(v0 - 1) = v1;
}
while ( v1 != (_DWORD)&unk_7A120 );
dword_F4890[0] = -1;
result = 0LL;
dcm_lru_first = 0;
dword_C6637C = -1;
dcm_lru_last = (int)&unk_7A11F;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int *v0; // rax
unsigned int v1; // edx
int v2; // ecx
__int64 result; // rax

memset(dcm_inodehash, 255, (size_t)&unk_F4240);
v0 = dcm_tab;
v1 = 0;
do
{
*v0 = 0;
v0 += 6;
LODWORD(qword_F4884[3 * v1]) &= 1u;
v2 = v1++ - 1;
*(v0 - 4) = -1;
*(v0 - 3) = -1;
*(v0 - 2) = v2;
*(v0 - 1) = v1;
}
while ( v1 != (_DWORD)&unk_7A120 );
dword_F4890[0] = -1;
result = 0LL;
dcm_lru_first = 0;
dword_C6637C = -1;
dcm_lru_last = (int)&unk_7A11F;
return result;
}

original_code:
int dcm_init(void) {
 uint32_t i;
 for (i=0 ; i<((500000)/2) ; i++) {
  dcm_inodehash[i]=0xFFFFFFFF;
 }
 for (i=0 ; i<500000 ; i++) {
  dcm_tab[i].inode=0;
  dcm_tab[i].sessionid=0;
  dcm_tab[i].iprev = 0xFFFFFFFF;
  dcm_tab[i].inext = 0xFFFFFFFF;
  dcm_tab[i].lruprev = i-1;
  dcm_tab[i].lrunext = i+1;
 }
 dcm_tab[0].lruprev = 0xFFFFFFFF;
 dcm_lru_first = 0;
 dcm_tab[500000 -1].lrunext = 0xFFFFFFFF;
 dcm_lru_last = 500000 -1;
 return 0;
}

canonical_original_code:
int dcm_init() {
 unsigned int i;
 for (i=0 ; i<((500000)/2) ; i++) {
  dcm_inodehash[i]=0xFFFFFFFF;
 }
 for (i=0 ; i<500000 ; i++) {
  dcm_tab[i].inode=0;
  dcm_tab[i].sessionid=0;
  dcm_tab[i].iprev = 0xFFFFFFFF;
  dcm_tab[i].inext = 0xFFFFFFFF;
  dcm_tab[i].lruprev = i-1;
  dcm_tab[i].lrunext = i+1;
 }
 dcm_tab[0].lruprev = 0xFFFFFFFF;
 dcm_lru_first = 0;
 dcm_tab[500000 -1].lrunext = 0xFFFFFFFF;
 dcm_lru_last = 500000 -1;
 return 0;
}

variable_types:
i
unsigned int

return_type: int


decompiled_code:
char *strerr_init()
{
__int64 v0; // rax
const char *i; // rdx
int v2; // ecx
unsigned int v3; // ebx
unsigned int v4; // eax
char *v5; // rax
unsigned int v6; // esi
const __m128i *v7; // r9
const char *v8; // r10
char *v9; // r8
int v10; // edi
int j; // edx
unsigned int v12; // edx
char *result; // rax

v0 = 1LL;
for ( i = "EACCES (Permission denied)"; ; i = (&off_1408)[2 * v0] )
{
v2 = v0++;
if ( !i )
break;
}
v3 = 1;
v4 = (unsigned int)(3 * v2) >> 1;
do
{
v3 *= 2;
v4 >>= 1;
}
while ( v4 );
errhsize = v3;
v5 = (char *)calloc(16LL * v3, 1uLL);
v6 = v3 - 1;
v7 = (const __m128i *)&errtab;
v8 = "EACCES (Permission denied)";
errhash = v5;
v9 = v5;
v10 = 7;
while ( 1 )
{
for ( j = 1905886897 * v10; ; j = (v6 & (760092119 * v10) | 1) + v12 )
{
v12 = v6 & j;
result = &v9[16 * v12];
if ( !*((_QWORD *)result + 1) )
break;
if ( *(_DWORD *)result == v10 )
goto LABEL_12;
}
*(__m128i *)result = _mm_load_si128(v7);
LABEL_12:
++v7;
if ( !v8 )
return result;
v10 = v7->m128i_i32[0];
v8 = (const char *)v7[1].m128i_i64[1];
}
}

canonical_decompiled_code:
char *func0()
{
__int64 v0; // rax
const char *i; // rdx
int v2; // ecx
unsigned int v3; // ebx
unsigned int v4; // eax
char *v5; // rax
unsigned int v6; // esi
const __m128i *v7; // r9
const char *v8; // r10
char *v9; // r8
int v10; // edi
int j; // edx
unsigned int v12; // edx
char *result; // rax

v0 = 1LL;
for ( i = "EACCES (Permission denied)"; ; i = (&off_1408)[2 * v0] )
{
v2 = v0++;
if ( !i )
break;
}
v3 = 1;
v4 = (unsigned int)(3 * v2) >> 1;
do
{
v3 *= 2;
v4 >>= 1;
}
while ( v4 );
errhsize = v3;
v5 = (char *)calloc(16LL * v3, 1uLL);
v6 = v3 - 1;
v7 = (const __m128i *)&errtab;
v8 = "EACCES (Permission denied)";
errhash = v5;
v9 = v5;
v10 = 7;
while ( 1 )
{
for ( j = 1905886897 * v10; ; j = (v6 & (760092119 * v10) | 1) + v12 )
{
v12 = v6 & j;
result = &v9[16 * v12];
if ( !*((_QWORD *)result + 1) )
break;
if ( *(_DWORD *)result == v10 )
goto LABEL_12;
}
*(__m128i *)result = _mm_load_si128(v7);
LABEL_12:
++v7;
if ( !v8 )
return result;
v10 = v7->m128i_i32[0];
v8 = (const char *)v7[1].m128i_i64[1];
}
}

original_code:
void strerr_init(void) {
 uint32_t n;
 uint32_t hash,disp;
 for (n=0 ; errtab[n].str ; n++) {}
 n = (n*3)/2;
 errhsize = 1;
 while (n>0) {
  errhsize<<=1;
  n>>=1;
 }
 errhash = malloc(sizeof(errent)*errhsize);
 memset(errhash,0,sizeof(errent)*errhsize);
 for (n=0 ; errtab[n].str ; n++) {
  hash = errtab[n].num;
  disp = ((hash * 760092119) & (errhsize-1)) | 1;
  hash = ((hash * 1905886897) & (errhsize-1));
  while (errhash[hash].str!=((void *)0) && errhash[hash].num != errtab[n].num) {
   hash+=disp;
   hash&=(errhsize-1);
  }
  if (errhash[hash].str==((void *)0)) {
   errhash[hash] = errtab[n];
  }
 }
}

canonical_original_code:
void strerr_init() {
 unsigned int n;
 unsigned int hash; unsigned int disp;
 for (n=0 ; errtab[n].str ; n++) {}
 n = (n*3)/2;
 errhsize = 1;
 while (n>0) {
  errhsize<<=1;
  n>>=1;
 }
 errhash = malloc(sizeof(errent)*errhsize);
 memset(errhash,0,sizeof(errent)*errhsize);
 for (n=0 ; errtab[n].str ; n++) {
  hash = errtab[n].num;
  disp = ((hash * 760092119) & (errhsize-1)) | 1;
  hash = ((hash * 1905886897) & (errhsize-1));
  while (errhash[hash].str!=((void *)0) && errhash[hash].num != errtab[n].num) {
   hash+=disp;
   hash&=(errhsize-1);
  }
  if (errhash[hash].str==((void *)0)) {
   errhash[hash] = errtab[n];
  }
 }
}

variable_types:
n
unsigned int

variable_types:
hash
unsigned int

variable_types:
disp
unsigned int


strerr

decompiled_code:
const char *__fastcall strerr(int a1)
{
unsigned int i; // edx
char *v2; // rax
__int64 v3; // r8

for ( i = (errhsize - 1) & (1905886897 * a1); ; i = (errhsize - 1) & (((errhsize - 1) & (760092119 * a1) | 1) + i) )
{
v2 = (char *)errhash + 16 * i;
v3 = *((_QWORD *)v2 + 1);
if ( !v3 )
break;
if ( *(_DWORD *)v2 == a1 )
return (const char *)v3;
}
return "Unknown error";
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
unsigned int i; // edx
char *v2; // rax
__int64 v3; // r8

for ( i = (errhsize - 1) & (1905886897 * a1); ; i = (errhsize - 1) & (((errhsize - 1) & (760092119 * a1) | 1) + i) )
{
v2 = (char *)errhash + 16 * i;
v3 = *((_QWORD *)v2 + 1);
if ( !v3 )
break;
if ( *(_DWORD *)v2 == a1 )
return (const char *)v3;
}
return "Unknown error";
}

original_code:
const char* strerr(int error) {
 uint32_t hash,disp;
 hash = error;
 disp = ((hash * 760092119) & (errhsize-1)) | 1;
 hash = ((hash * 1905886897) & (errhsize-1));
 while (errhash[hash].str!=((void *)0)) {
  if (errhash[hash].num == error) {
   return errhash[hash].str;
  }
  hash+=disp;
  hash&=(errhsize-1);
 }
 return "Unknown error";
}

canonical_original_code:
char *strerr(int error) {
 unsigned int hash; unsigned int disp;
 hash = error;
 disp = ((hash * 760092119) & (errhsize-1)) | 1;
 hash = ((hash * 1905886897) & (errhsize-1));
 while (errhash[hash].str!=((void *)0)) {
  if (errhash[hash].num == error) {
   return errhash[hash].str;
  }
  hash+=disp;
  hash&=(errhsize-1);
 }
 return "Unknown error";
}

variable_types: error int

return_type: char *


decompiled_code:
void strerr_term()
{
free(errhash);
}

canonical_decompiled_code:
void func2()
{
free(errhash);
}

original_code:
void strerr_term(void) {
 free(errhash);
}

canonical_original_code:
void strerr_term() {
 free(errhash);
}


decompiled_code:
// attributes: thunk
__int64 chartsdata_store()
{
return charts_store();
}

canonical_decompiled_code:
__int64 func1()
{
return charts_store();
}

original_code:
void chartsdata_store(void) {
 charts_store();
}

canonical_original_code:
void chartsdata_store() {
 charts_store();
}


decompiled_code:
__int64 chartsdata_term()
{
chartsdata_refresh();
charts_store();
return charts_term();
}

canonical_decompiled_code:
__int64 func2()
{
func0();
charts_store();
return charts_term();
}

original_code:
void chartsdata_term(void) {
 chartsdata_refresh();
 charts_store();
 charts_term();
}

canonical_original_code:
void chartsdata_term() {
 chartsdata_refresh();
 charts_store();
 charts_term();
}


decompiled_code:
__int64 chartsdata_memusage()
{
return memusage;
}

canonical_decompiled_code:
__int64 func3()
{
return memusage;
}

original_code:
uint64_t chartsdata_memusage(void) {
 return memusage;
}

canonical_original_code:
unsigned long chartsdata_memusage() {
 return memusage;
}

return_type: unsigned long


variable_types:
ptr
unsigned char **

variable_types:
val
unsigned long


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

result = a2;
**(_BYTE **)a1 = HIBYTE(a2);
*(_BYTE *)(*(_QWORD *)a1 + 1LL) = BYTE2(a2);
*(_BYTE *)(*(_QWORD *)a1 + 2LL) = BYTE1(a2);
*(_BYTE *)(*(_QWORD *)a1 + 3LL) = a2;
*(_QWORD *)a1 += 4LL;
return result;
}

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

result = a2;
**(_BYTE **)a1 = HIBYTE(a2);
*(_BYTE *)(*(_QWORD *)a1 + 1LL) = BYTE2(a2);
*(_BYTE *)(*(_QWORD *)a1 + 2LL) = BYTE1(a2);
*(_BYTE *)(*(_QWORD *)a1 + 3LL) = a2;
*(_QWORD *)a1 += 4LL;
return result;
}

canonical_original_code:
static inline void put32bit(unsigned char **ptr, unsigned int val) {
 (*ptr)[0]=((val)>>24)&0xFF;
 (*ptr)[1]=((val)>>16)&0xFF;
 (*ptr)[2]=((val)>>8)&0xFF;
 (*ptr)[3]=(val)&0xFF;
 (*ptr)+=4;
}

variable_types:
val
unsigned int


canonical_original_code:
static inline unsigned int get32bit(unsigned char **ptr) {
 unsigned int t32;
 t32=((*ptr)[3]+256U*((*ptr)[2]+256U*((*ptr)[1]+256U*(*ptr)[0])));
 (*ptr)+=4;
 return t32;
}

return_type: unsigned int


decompiled_code:
char *chunk_malloc()
{
char *result; // rax
char *v1; // rbx
int v2; // edx

result = (char *)chfreehead;
if ( chfreehead )
{
chfreehead = *(_QWORD *)(chfreehead + 32);
}
else
{
v1 = (char *)cbhead;
if ( !cbhead || (v2 = *(int *)((char *)&dword_C3500 + (_QWORD)cbhead), v2 == 20000) )
{
result = (char *)malloc((size_t)&unk_C3510);
if ( !result )
{
fprintf(stderr, "out of memory: %s is NULL\n", "cb");
syslog(3, "out of memory: %s is NULL", "cb");
abort();
}
*(__int64 *)((char *)&qword_C3508 + (_QWORD)result) = (__int64)v1;
*(int *)((char *)&dword_C3500 + (_QWORD)result) = 0;
cbhead = result;
*(int *)((char *)&dword_C3500 + (_QWORD)result) = 1;
}
else
{
*(int *)((char *)&dword_C3500 + (_QWORD)cbhead) = v2 + 1;
result = &v1[40 * v2];
}
}
return result;
}

canonical_decompiled_code:
char *func4()
{
char *result; // rax
char *v1; // rbx
int v2; // edx

result = (char *)chfreehead;
if ( chfreehead )
{
chfreehead = *(_QWORD *)(chfreehead + 32);
}
else
{
v1 = (char *)cbhead;
if ( !cbhead || (v2 = *(int *)((char *)&dword_C3500 + (_QWORD)cbhead), v2 == 20000) )
{
result = (char *)malloc((size_t)&unk_C3510);
if ( !result )
{
fprintf(stderr, "out of memory: %s is NULL\n", "cb");
syslog(3, "out of memory: %s is NULL", "cb");
abort();
}
*(__int64 *)((char *)&qword_C3508 + (_QWORD)result) = (__int64)v1;
*(int *)((char *)&dword_C3500 + (_QWORD)result) = 0;
cbhead = result;
*(int *)((char *)&dword_C3500 + (_QWORD)result) = 1;
}
else
{
*(int *)((char *)&dword_C3500 + (_QWORD)cbhead) = v2 + 1;
result = &v1[40 * v2];
}
}
return result;
}

original_code:
static inline chunk* chunk_malloc() {
 chunk_bucket *cb;
 chunk *ret;
 if (chfreehead) {
  ret = chfreehead;
  chfreehead = ret->next;
  return ret;
 }
 if (cbhead==((void *)0) || cbhead->firstfree==20000) {
  cb = (chunk_bucket*)malloc(sizeof(chunk_bucket));
  ((cb!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","cb"),syslog(3,"out of memory: %s is NULL","cb"),abort()));
  cb->next = cbhead;
  cb->firstfree = 0;
  cbhead = cb;
 }
 ret = (cbhead->bucket)+(cbhead->firstfree);
 cbhead->firstfree++;
 return ret;
}

canonical_original_code:
static inline struct chunk *chunk_malloc() {
 struct _chunk_bucket *cb;
 struct chunk *ret;
 if (chfreehead) {
  ret = chfreehead;
  chfreehead = ret->next;
  return ret;
 }
 if (cbhead==((void *)0) || cbhead->firstfree==20000) {
  cb = (struct _chunk_bucket *)malloc(sizeof(chunk_bucket));
  ((cb!=((void *)0)) ? (void)0 : (fprintf(stderr,"out of memory: %s is NULL\n","cb"),syslog(3,"out of memory: %s is NULL","cb"),abort()));
  cb->next = cbhead;
  cb->firstfree = 0;
  cbhead = cb;
 }
 ret = (cbhead->bucket)+(cbhead->firstfree);
 cbhead->firstfree++;
 return ret;
}

variable_types: struct _chunk_bucket { struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned char allvalidcopies; unsigned char regularvalidcopies; unsigned int needverincrease; unsigned int interrupted; unsigned int operation; unsigned int lockedto; unsigned int fcount; struct _slist { void *ptr; unsigned char valid; unsigned int version; struct _slist *next; } *slisthead; unsigned int *ftab; struct chunk *next; } bucket[20000]; unsigned int firstfree; struct _chunk_bucket *next; } *

variable_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned char allvalidcopies; unsigned char regularvalidcopies; unsigned int needverincrease; unsigned int interrupted; unsigned int operation; unsigned int lockedto; unsigned int fcount; struct _slist { void *ptr; unsigned char valid; unsigned int version; struct _slist *next; } *slisthead; unsigned int *ftab; struct chunk *next; } *

user_defined_types: struct _chunk_bucket { struct chunk bucket[20000]; unsigned int firstfree; struct _chunk_bucket *next; }

user_defined_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned char allvalidcopies; unsigned char regularvalidcopies; unsigned int needverincrease; unsigned int interrupted; unsigned int operation; unsigned int lockedto; unsigned int fcount; struct _slist *slisthead; unsigned int *ftab; struct chunk *next; }


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

v2 = chunk_find(a1);
if ( v2 )
result = chunk_delete_file_int(v2, a2);
else
result = 13LL;
return result;
}

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

v2 = chunk_find(a1);
if ( v2 )
result = func6(v2, a2);
else
result = 13LL;
return result;
}

original_code:
int chunk_delete_file(uint64_t chunkid,uint8_t goal) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_delete_file_int(c,goal);
}

canonical_original_code:
int chunk_delete_file(unsigned long chunkid, unsigned char goal) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_delete_file_int(c,goal);
}

variable_types:
chunkid
unsigned long

variable_types:
goal
unsigned char

user_defined_types: struct _slist { void *ptr; unsigned char valid; unsigned int version; struct _slist *next; }


decompiled_code:
__int64 __fastcall chunk_add_file(__int64 a1, unsigned __int8 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = chunk_find(a1);
if ( v2 )
result = chunk_add_file_int((__int64)v2, a2);
else
result = 13LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int8 a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = chunk_find(a1);
if ( v2 )
result = func5((__int64)v2, a2);
else
result = 13LL;
return result;
}

original_code:
int chunk_add_file(uint64_t chunkid,uint8_t goal) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_add_file_int(c,goal);
}

canonical_original_code:
int chunk_add_file(unsigned long chunkid, unsigned char goal) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 return chunk_add_file_int(c,goal);
}


decompiled_code:
__int64 __fastcall chunk_unlock(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
*((_DWORD *)v1 + 4) = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
*((_DWORD *)v1 + 4) = 0;
return 0LL;
}

original_code:
int chunk_unlock(uint64_t chunkid) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->lockedto=0;
 return 0;
}

canonical_original_code:
int chunk_unlock(unsigned long chunkid) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->lockedto=0;
 return 0;
}


decompiled_code:
__int64 __fastcall chunk_set_version(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = chunk_find(a1);
if ( !v2 )
return 13LL;
*((_DWORD *)v2 + 2) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = chunk_find(a1);
if ( !v2 )
return 13LL;
*((_DWORD *)v2 + 2) = a2;
return 0LL;
}

original_code:
int chunk_set_version(uint64_t chunkid,uint32_t version) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version = version;
 return 0;
}

canonical_original_code:
int chunk_set_version(unsigned long chunkid, unsigned int version) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version = version;
 return 0;
}

variable_types:
version
unsigned int

variable_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned int lockedto; unsigned int fcount; unsigned int *ftab; struct chunk *next; } *


decompiled_code:
__int64 __fastcall chunk_increase_version(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
++*((_DWORD *)v1 + 2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
_QWORD *v1; // rax

v1 = chunk_find(a1);
if ( !v1 )
return 13LL;
++*((_DWORD *)v1 + 2);
return 0LL;
}

original_code:
int chunk_increase_version(uint64_t chunkid) {
 chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version++;
 return 0;
}

canonical_original_code:
int chunk_increase_version(unsigned long chunkid) {
 struct chunk *c;
 c = chunk_find(chunkid);
 if (c==((void *)0)) {
  return 13;
 }
 c->version++;
 return 0;
}

user_defined_types: struct chunk { unsigned long chunkid; unsigned int version; unsigned char goal; unsigned int lockedto; unsigned int fcount; unsigned int *ftab; struct chunk *next; }


decompiled_code:
unsigned int chunk_dump()
{
__int64 *v0; // r13
unsigned int result; // eax
unsigned int v2; // ebp
__int64 i; // rbx
__int64 v4; // r8

v0 = chunkhash;
result = time(0LL);
v2 = result;
do
{
for ( i = *v0; i; i = *(_QWORD *)(i + 32) )
{
v4 = *(unsigned int *)(i + 16);
if ( v2 > (unsigned int)v4 )
v4 = 0LL;
result = printf(
"*|i:%016lX|v:%08X|g:%u|t:%10u\n",
*(_QWORD *)i,
*(unsigned int *)(i + 8),
*(unsigned __int8 *)(i + 12),
v4);
}
++v0;
}
while ( v0 != &chfreehead );
return result;
}

canonical_decompiled_code:
unsigned int func16()
{
__int64 *v0; // r13
unsigned int result; // eax
unsigned int v2; // ebp
__int64 i; // rbx
__int64 v4; // r8

v0 = chunkhash;
result = time(0LL);
v2 = result;
do
{
for ( i = *v0; i; i = *(_QWORD *)(i + 32) )
{
v4 = *(unsigned int *)(i + 16);
if ( v2 > (unsigned int)v4 )
v4 = 0LL;
result = printf(
"*|i:%016lX|v:%08X|g:%u|t:%10u\n",
*(_QWORD *)i,
*(unsigned int *)(i + 8),
*(unsigned __int8 *)(i + 12),
v4);
}
++v0;
}
while ( v0 != &chfreehead );
return result;
}

original_code:
void chunk_dump(void) {
 chunk *c;
 uint32_t i,lockedto,now;
 now = time(((void *)0));
 for (i=0 ; i<0x100000 ; i++) {
  for (c=chunkhash[i] ; c ; c=c->next) {
   lockedto = c->lockedto;
   if (lockedto<now) {
    lockedto = 0;
   }
   printf("*|i:%016""l" "X""|v:%08""X""|g:%""u""|t:%10""u""\n",c->chunkid,c->version,c->goal,lockedto);
  }
 }
}

canonical_original_code:
void chunk_dump() {
 struct chunk *c;
 unsigned int i; unsigned int lockedto; unsigned int now;
 now = time(((void *)0));
 for (i=0 ; i<0x100000 ; i++) {
  for (c=chunkhash[i] ; c ; c=c->next) {
   lockedto = c->lockedto;
   if (lockedto<now) {
    lockedto = 0;
   }
   printf("*|i:%016""l" "X""|v:%08""X""|g:%""u""|t:%10""u""\n",c->chunkid,c->version,c->goal,lockedto);
  }
 }
}

variable_types:
lockedto
unsigned int

variable_types:
now
unsigned int


decompiled_code:
__int64 __fastcall merger_nextentry(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 result; // rax
__int64 v4; // rdx

v1 = 40LL * a1;
if ( fgets(*(char **)(v1 + heap + 16), 200000, *(FILE **)(v1 + heap)) )
{
v2 = v1 + heap;
result = strtoll(*(const char **)(v1 + heap + 16), (char **)(v1 + heap + 24), 10);
v4 = *(_QWORD *)(v2 + 32);
if ( v4 >= 0 && (v4 >= result || v4 + maxidhole <= result) )
{
printf("found garbage at the end of file: %s (last correct id: %lu)\n", *(const char **)(v2 + 8), v4);
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
else
{
*(_QWORD *)(v2 + 32) = result;
}
}
else
{
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 result; // rax
__int64 v4; // rdx

v1 = 40LL * a1;
if ( fgets(*(char **)(v1 + heap + 16), 200000, *(FILE **)(v1 + heap)) )
{
v2 = v1 + heap;
result = strtoll(*(const char **)(v1 + heap + 16), (char **)(v1 + heap + 24), 10);
v4 = *(_QWORD *)(v2 + 32);
if ( v4 >= 0 && (v4 >= result || v4 + maxidhole <= result) )
{
printf("found garbage at the end of file: %s (last correct id: %lu)\n", *(const char **)(v2 + 8), v4);
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
else
{
*(_QWORD *)(v2 + 32) = result;
}
}
else
{
result = heap;
*(_QWORD *)(heap + v1 + 32) = -1LL;
}
return result;
}

original_code:
void merger_nextentry(uint32_t pos) {
 if (fgets(heap[pos].buff,200000,heap[pos].fd)) {
  int64_t nextid = strtoll(heap[pos].buff,&(heap[pos].ptr),10);
  if (heap[pos].nextid<0 || (nextid>heap[pos].nextid && nextid<heap[pos].nextid+maxidhole)) {
   heap[pos].nextid = nextid;
  } else {
   printf("found garbage at the end of file: %s (last correct id: %""l" "u"")\n",heap[pos].filename,heap[pos].nextid);
   heap[pos].nextid = -1L;
  }
 } else {
  heap[pos].nextid = -1L;
 }
}

canonical_original_code:
void merger_nextentry(unsigned int pos) {
 if (fgets(heap[pos].buff,200000,heap[pos].fd)) {
  long nextid = strtoll(heap[pos].buff,&(heap[pos].ptr),10);
  if (heap[pos].nextid<0 || (nextid>heap[pos].nextid && nextid<heap[pos].nextid+maxidhole)) {
   heap[pos].nextid = nextid;
  } else {
   printf("found garbage at the end of file: %s (last correct id: %""l" "u"")\n",heap[pos].filename,heap[pos].nextid);
   heap[pos].nextid = -1L;
  }
 } else {
  heap[pos].nextid = -1L;
 }
}

variable_types:
pos
unsigned int

variable_types: nextid long


decompiled_code:
void merger_delete_entry()
{
__int64 v0; // rbx
void *v1; // rdi
void *v2; // rdi

v0 = heap + 40LL * (unsigned int)heapsize;
if ( *(_QWORD *)v0 )
{
fclose(*(FILE **)v0);
v0 = heap + 40LL * (unsigned int)heapsize;
}
v1 = *(void **)(v0 + 8);
if ( v1 )
free(v1);
v2 = *(void **)(v0 + 16);
if ( v2 )
free(v2);
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rbx
void *v1; // rdi
void *v2; // rdi

v0 = heap + 40LL * (unsigned int)heapsize;
if ( *(_QWORD *)v0 )
{
fclose(*(FILE **)v0);
v0 = heap + 40LL * (unsigned int)heapsize;
}
v1 = *(void **)(v0 + 8);
if ( v1 )
free(v1);
v2 = *(void **)(v0 + 16);
if ( v2 )
free(v2);
}

original_code:
void merger_delete_entry(void) {
 if (heap[heapsize].fd) {
  fclose(heap[heapsize].fd);
 }
 if (heap[heapsize].filename) {
  free(heap[heapsize].filename);
 }
 if (heap[heapsize].buff) {
  free(heap[heapsize].buff);
 }
}

canonical_original_code:
void merger_delete_entry() {
 if (heap[heapsize].fd) {
  fclose(heap[heapsize].fd);
 }
 if (heap[heapsize].filename) {
  free(heap[heapsize].filename);
 }
 if (heap[heapsize].buff) {
  free(heap[heapsize].buff);
 }
}


quit

decompiled_code:
void __fastcall __noreturn quit(int a1)
{
puts("Server is shutting down");
close(sockfd);
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
puts("Server is shutting down");
close(sockfd);
exit(a1);
}

original_code:
void quit(int sig) {
 printf("Server is shutting down\n");
 close(sockfd);
 exit(sig);
}

variable_types: sig int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
socklen_t v3; // edx
int v4; // er8
int *v5; // rax
int v6; // ebp
unsigned __int16 v7; // bx
char *v8; // rax
char *v9; // rax
int v10; // ebx
char *v11; // r14
char *i; // rdi
struct tm *v13; // rax
struct tm *v14; // rdi
__int64 v15; // rcx
struct tm *v16; // rsi
size_t v17; // rax
char *v18; // rax
__m128i v19; // xmm0
struct tm *v20; // rax
__int64 v21; // rcx
struct tm *v22; // rdi
struct tm *v23; // rsi
size_t v24; // rax
char *v25; // rax
__m128i v26; // xmm0
FILE *v27; // rdi
__int64 v28; // rax
size_t v29; // rax
int *v30; // rax
int *v31; // rax
int *v32; // rax
int *v33; // rax
int *v34; // rax
struct tm *v35; // rax
struct tm *v36; // rdi
__int64 v37; // rcx
struct tm *v38; // rsi
size_t v39; // rax
socklen_t addr_len; // [rsp+4h] [rbp-A24h] BYREF
time_t timer; // [rsp+8h] [rbp-A20h] BYREF
struct sockaddr v42; // [rsp+10h] [rbp-A18h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A08h] BYREF
struct tm tp; // [rsp+30h] [rbp-9F8h] BYREF
struct stat v45; // [rsp+70h] [rbp-9B8h] BYREF
char dest[256]; // [rsp+100h] [rbp-928h] BYREF
__int128 buf[130]; // [rsp+200h] [rbp-828h] BYREF

signal(2, (__sighandler_t)quit);
sockfd = socket(2, 1, 0);
if ( sockfd >= 0 )
{
v42 = 0LL;
v42.sa_family = 2;
*(_WORD *)v42.sa_data = _bswap_16(3456);
if ( bind(v4, &v42, v3) )
{
perror("Error binding");
v5 = _errno_location();
exit(*v5);
}
if ( !listen(sockfd, 10) )
{
puts("Server is now listening for connections");
puts("Press CTRL-c to stop the server");
while ( 1 )
{
addr_len = 16;
v6 = accept(sockfd, &addr, &addr_len);
v7 = _bswap_16(*(__int16 *)addr.sa_data);
v8 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("%s:%d connected\n", v8, v7);
if ( !fork() )
break;
if ( close(v6) < 0 )
{
perror("Error closing client connection in parent.");
v32 = _errno_location();
exit(*v32);
}
waitpid(-1, 0LL, 1);
}
if ( close(sockfd) >= 0 )
{
memset(buf, 0, 0x800uLL);
memset(dest, 0, sizeof(dest));
recv(v6, buf, 0x800uLL, 0);
printf("Client request:\n%s\n", (const char *)buf);
v9 = strtok((char *)buf, " ");
v10 = strcmp(v9, "GET");
v11 = strtok(0LL, " ");
strtok(0LL, "\r");
strtok(0LL, "\n");
strtok(0LL, "\n");
for ( i = strtok(0LL, "\n"); strlen(i) > 1; i = strtok(0LL, "\n") )
;
dest[0] = 46;
strcat(dest, v11);
file = fopen(dest, "r");
memset(buf, 0, 0x800uLL);
memset(dest, 0, sizeof(dest));
if ( file )
{
stat(dest, &v45);
LOWORD(buf[1]) = 10;
buf[0] = (__int128)_mm_load_si128((const __m128i *)&LC23);
strcat((char *)buf, "Date: ");
time(&timer);
v13 = gmtime(&timer);
v14 = &tp;
v15 = 14LL;
v16 = v13;
while ( v15 )
{
v14->tm_sec = v16->tm_sec;
v16 = (struct tm *)((char *)v16 + 4);
v14 = (struct tm *)((char *)v14 + 4);
--v15;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
v17 = strlen((const char *)buf);
v18 = stpcpy((char *)buf + v17, dest);
v19 = _mm_load_si128((const __m128i *)&LC24);
*(_WORD *)v18 = 2573;
*(__m128i *)(v18 + 2) = v19;
v20 = gmtime(&v45.st_mtim.tv_sec);
v21 = 14LL;
v22 = &tp;
v23 = v20;
while ( v21 )
{
v22->tm_sec = v23->tm_sec;
v23 = (struct tm *)((char *)v23 + 4);
v22 = (struct tm *)((char *)v22 + 4);
--v21;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
v24 = strlen((const char *)buf);
v25 = stpcpy((char *)buf + v24, dest);
v26 = _mm_load_si128((const __m128i *)&LC25);
qmemcpy(v25, "\r\nContent-Type: text/html\r\n", 27);
v25[43] = 0;
v27 = file;
*(__m128i *)(v25 + 27) = v26;
fseek(v27, 0LL, 2);
v28 = ftell(file);
sprintf(dest, "%ld", v28);
fseek(file, 0LL, 0);
v29 = strlen((const char *)buf);
strcpy(stpcpy((char *)buf + v29, dest), "\r\nConnection: close\r\n\r\n");
if ( !v10 )
{
fread(dest, 1uLL, v45.st_size, file);
strcat((char *)buf, dest);
}
fclose(file);
}
else
{
strcpy((char *)buf, "HTTP/1.1 404 Not Found\r\n");
strcat((char *)buf, "Date: ");
time(&timer);
v35 = gmtime(&timer);
v36 = &tp;
v37 = 14LL;
v38 = v35;
while ( v37 )
{
v36->tm_sec = v38->tm_sec;
v38 = (struct tm *)((char *)v38 + 4);
v36 = (struct tm *)((char *)v36 + 4);
--v37;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
v39 = strlen((const char *)buf);
strcpy(stpcpy((char *)buf + v39, dest), "\r\nConnection: close\r\n\r\n");
}
printf("Server response:\n%s\n", (const char *)buf);
send(v6, buf, 0x800uLL, 0);
if ( close(v6) >= 0 )
exit(0);
perror("Error closing client connection.");
v34 = _errno_location();
exit(*v34);
}
perror("Error closing server socket in child process serving client.");
v33 = _errno_location();
exit(*v33);
}
perror("Error listening");
v31 = _errno_location();
exit(*v31);
}
perror("Error creating file descriptor for socket");
v30 = _errno_location();
exit(*v30);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
socklen_t v3; // edx
int v4; // er8
int *v5; // rax
int v6; // ebp
unsigned __int16 v7; // bx
char *v8; // rax
char *v9; // rax
int v10; // ebx
char *v11; // r14
char *i; // rdi
struct tm *v13; // rax
struct tm *v14; // rdi
__int64 v15; // rcx
struct tm *v16; // rsi
size_t v17; // rax
char *v18; // rax
__m128i v19; // xmm0
struct tm *v20; // rax
__int64 v21; // rcx
struct tm *v22; // rdi
struct tm *v23; // rsi
size_t v24; // rax
char *v25; // rax
__m128i v26; // xmm0
FILE *v27; // rdi
__int64 v28; // rax
size_t v29; // rax
int *v30; // rax
int *v31; // rax
int *v32; // rax
int *v33; // rax
int *v34; // rax
struct tm *v35; // rax
struct tm *v36; // rdi
__int64 v37; // rcx
struct tm *v38; // rsi
size_t v39; // rax
socklen_t addr_len; // [rsp+4h] [rbp-A24h] BYREF
time_t timer; // [rsp+8h] [rbp-A20h] BYREF
struct sockaddr v42; // [rsp+10h] [rbp-A18h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-A08h] BYREF
struct tm tp; // [rsp+30h] [rbp-9F8h] BYREF
struct stat v45; // [rsp+70h] [rbp-9B8h] BYREF
char dest[256]; // [rsp+100h] [rbp-928h] BYREF
__int128 buf[130]; // [rsp+200h] [rbp-828h] BYREF

signal(2, (__sighandler_t)quit);
sockfd = socket(2, 1, 0);
if ( sockfd >= 0 )
{
v42 = 0LL;
v42.sa_family = 2;
*(_WORD *)v42.sa_data = func1(3456);
if ( bind(v4, &v42, v3) )
{
perror("Error binding");
v5 = _errno_location();
exit(*v5);
}
if ( !listen(sockfd, 10) )
{
puts("Server is now listening for connections");
puts("Press CTRL-c to stop the server");
while ( 1 )
{
addr_len = 16;
v6 = accept(sockfd, &addr, &addr_len);
v7 = func1(*(__int16 *)addr.sa_data);
v8 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("%s:%d connected\n", v8, v7);
if ( !fork() )
break;
if ( close(v6) < 0 )
{
perror("Error closing client connection in parent.");
v32 = _errno_location();
exit(*v32);
}
waitpid(-1, 0LL, 1);
}
if ( close(sockfd) >= 0 )
{
memset(buf, 0, 0x800uLL);
memset(dest, 0, sizeof(dest));
recv(v6, buf, 0x800uLL, 0);
printf("Client request:\n%s\n", (const char *)buf);
v9 = strtok((char *)buf, " ");
v10 = strcmp(v9, "GET");
v11 = strtok(0LL, " ");
strtok(0LL, "\r");
strtok(0LL, "\n");
strtok(0LL, "\n");
for ( i = strtok(0LL, "\n"); strlen(i) > 1; i = strtok(0LL, "\n") )
;
dest[0] = 46;
strcat(dest, v11);
file = fopen(dest, "r");
memset(buf, 0, 0x800uLL);
memset(dest, 0, sizeof(dest));
if ( file )
{
stat(dest, &v45);
LOWORD(buf[1]) = 10;
buf[0] = (__int128)_mm_load_si128((const __m128i *)&LC23);
strcat((char *)buf, "Date: ");
time(&timer);
v13 = gmtime(&timer);
v14 = &tp;
v15 = 14LL;
v16 = v13;
while ( v15 )
{
v14->tm_sec = v16->tm_sec;
v16 = (struct tm *)((char *)v16 + 4);
v14 = (struct tm *)((char *)v14 + 4);
--v15;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
v17 = strlen((const char *)buf);
v18 = stpcpy((char *)buf + v17, dest);
v19 = _mm_load_si128((const __m128i *)&LC24);
*(_WORD *)v18 = 2573;
*(__m128i *)(v18 + 2) = v19;
v20 = gmtime(&v45.st_mtim.tv_sec);
v21 = 14LL;
v22 = &tp;
v23 = v20;
while ( v21 )
{
v22->tm_sec = v23->tm_sec;
v23 = (struct tm *)((char *)v23 + 4);
v22 = (struct tm *)((char *)v22 + 4);
--v21;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
v24 = strlen((const char *)buf);
v25 = stpcpy((char *)buf + v24, dest);
v26 = _mm_load_si128((const __m128i *)&LC25);
qmemcpy(v25, "\r\nContent-Type: text/html\r\n", 27);
v25[43] = 0;
v27 = file;
*(__m128i *)(v25 + 27) = v26;
fseek(v27, 0LL, 2);
v28 = ftell(file);
sprintf(dest, "%ld", v28);
fseek(file, 0LL, 0);
v29 = strlen((const char *)buf);
strcpy(stpcpy((char *)buf + v29, dest), "\r\nConnection: close\r\n\r\n");
if ( !v10 )
{
fread(dest, 1uLL, v45.st_size, file);
strcat((char *)buf, dest);
}
fclose(file);
}
else
{
strcpy((char *)buf, "HTTP/1.1 404 Not Found\r\n");
strcat((char *)buf, "Date: ");
time(&timer);
v35 = gmtime(&timer);
v36 = &tp;
v37 = 14LL;
v38 = v35;
while ( v37 )
{
v36->tm_sec = v38->tm_sec;
v38 = (struct tm *)((char *)v38 + 4);
v36 = (struct tm *)((char *)v36 + 4);
--v37;
}
strftime(dest, 0x100uLL, "%a, %d %b %Y %H:%M:%S %Z", &tp);
v39 = strlen((const char *)buf);
strcpy(stpcpy((char *)buf + v39, dest), "\r\nConnection: close\r\n\r\n");
}
printf("Server response:\n%s\n", (const char *)buf);
send(v6, buf, 0x800uLL, 0);
if ( close(v6) >= 0 )
exit(0);
perror("Error closing client connection.");
v34 = _errno_location();
exit(*v34);
}
perror("Error closing server socket in child process serving client.");
v33 = _errno_location();
exit(*v33);
}
perror("Error listening");
v31 = _errno_location();
exit(*v31);
}
perror("Error creating file descriptor for socket");
v30 = _errno_location();
exit(*v30);
}

original_code:
int main()
{
 signal(2, quit);
 struct sockaddr_in server;
 char buffer[2048];
 pid_t pid;
 if ((sockfd = socket(2, SOCK_STREAM, 0)) < 0)
 {
  perror("Error creating file descriptor for socket");
  exit((*__errno_location ()));
 }
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_port = htons(3456);
 server.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) != 0)
 {
  perror("Error binding");
  exit((*__errno_location ()));
    }
 if (listen(sockfd,10) != 0)
 {
  perror("Error listening");
  exit((*__errno_location ()));
    }
 printf("Server is now listening for connections\n");
 printf("Press CTRL-c to stop the server\n");
 while(1)
 {
  int clientfd;
  struct sockaddr_in client;
  unsigned int clientlen = sizeof(client);
  clientfd = accept(sockfd,(struct sockaddr *)&client, &clientlen);
  printf("%s:%d connected\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));
  pid = fork();
  if (pid == 0) {
   if ( close(sockfd) < 0 ) {
    perror("Error closing server socket in child process serving client.");
    exit((*__errno_location ()));
   }
   char *type;
   int req;
   char *res;
   char *version;
   char *line;
   char buf2[256];
   memset(buffer,0,2048);
   memset(buf2,0,256);
   recv(clientfd,buffer,2048,0);
   printf("Client request:\n%s\n",buffer);
   type = strtok(buffer," ");
   if(strcmp(type,"HEAD")==0)
     req = 0;
   if(strcmp(type,"GET")==0)
     req = 1;
   res = strtok(((void *)0)," ");
   version = strtok(((void *)0),"\r");
   strtok(((void *)0),"\n");
   strtok(((void *)0),"\n");
   line = strtok(((void *)0),"\n");
   while(strlen(line)>1)
    {
      line = strtok(((void *)0),"\n");
    }
   if( req==0 || req==1 )
   {
    char *directory;
    struct tm timeinfo;
    time_t rawtime;
    buf2[0] = '.';
    directory = strcat(buf2,res);
    file = fopen(directory,"r");
    memset(buffer,0,2048);
    memset(buf2,0,256);
    if(file==((void *)0))
    {
     sprintf(buffer,"HTTP/1.1 404 Not Found\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
    }
    else {
     struct stat fstat;
     stat(directory,&fstat);
     sprintf(buffer,"HTTP/1.1 200 OK\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Last-Modified: ");
     timeinfo = *gmtime(&(fstat.st_mtim.tv_sec));
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Content-Type: text/html\r\n");
     strcat(buffer,"Content-Length: ");
     fseek(file, 0L, 2);
     sprintf(buf2,"%ld",ftell(file));
     fseek(file, 0L, 0);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
     if(req==1)
       {
         fread(buf2,1,fstat.st_size,file);
         strcat(buffer,buf2);
       }
     fclose(file);
    }
   }
   printf("Server response:\n%s\n",buffer);
   send(clientfd, buffer, 2048, 0);
   if ( close(clientfd) < 0 ) {
    perror("Error closing client connection.");
    exit((*__errno_location ()));
   }
   exit(0);
  }
  if ( close(clientfd) < 0 ) {
   perror("Error closing client connection in parent.");
   exit((*__errno_location ()));
  }
  waitpid(-1, ((void *)0), 1);
 }
 return 0;
}

canonical_original_code:
int main()
{
 signal(2, quit);
 struct sockaddr_in server;
 char buffer[2048];
 int pid;
 if ((sockfd = socket(2, SOCK_STREAM, 0)) < 0)
 {
  perror("Error creating file descriptor for socket");
  exit((*__errno_location ()));
 }
 memset(&server, 0, sizeof(server));
 server.sin_family = 2;
 server.sin_port = htons(3456);
 server.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) != 0)
 {
  perror("Error binding");
  exit((*__errno_location ()));
    }
 if (listen(sockfd,10) != 0)
 {
  perror("Error listening");
  exit((*__errno_location ()));
    }
 printf("Server is now listening for connections\n");
 printf("Press CTRL-c to stop the server\n");
 while(1)
 {
  int clientfd;
  struct sockaddr_in client;
  unsigned int clientlen = sizeof(client);
  clientfd = accept(sockfd,(struct sockaddr *)&client, &clientlen);
  printf("%s:%d connected\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));
  pid = fork();
  if (pid == 0) {
   if ( close(sockfd) < 0 ) {
    perror("Error closing server socket in child process serving client.");
    exit((*__errno_location ()));
   }
   char *type;
   int req;
   char *res;
   char *version;
   char *line;
   char buf2[256];
   memset(buffer,0,2048);
   memset(buf2,0,256);
   recv(clientfd,buffer,2048,0);
   printf("Client request:\n%s\n",buffer);
   type = strtok(buffer," ");
   if(strcmp(type,"HEAD")==0)
     req = 0;
   if(strcmp(type,"GET")==0)
     req = 1;
   res = strtok(((void *)0)," ");
   version = strtok(((void *)0),"\r");
   strtok(((void *)0),"\n");
   strtok(((void *)0),"\n");
   line = strtok(((void *)0),"\n");
   while(strlen(line)>1)
    {
      line = strtok(((void *)0),"\n");
    }
   if( req==0 || req==1 )
   {
    char *directory;
    struct tm timeinfo;
    long rawtime;
    buf2[0] = '.';
    directory = strcat(buf2,res);
    file = fopen(directory,"r");
    memset(buffer,0,2048);
    memset(buf2,0,256);
    if(file==((void *)0))
    {
     sprintf(buffer,"HTTP/1.1 404 Not Found\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
    }
    else {
     struct stat fstat;
     stat(directory,&fstat);
     sprintf(buffer,"HTTP/1.1 200 OK\r\n");
     strcat(buffer,"Date: ");
     time(&rawtime);
     timeinfo = *gmtime(&rawtime);
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Last-Modified: ");
     timeinfo = *gmtime(&(fstat.st_mtim.tv_sec));
     strftime(buf2,sizeof(buf2), "%a, %d %b %Y %H:%M:%S %Z",&timeinfo);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Content-Type: text/html\r\n");
     strcat(buffer,"Content-Length: ");
     fseek(file, 0L, 2);
     sprintf(buf2,"%ld",ftell(file));
     fseek(file, 0L, 0);
     strcat(buffer,buf2);
     strcat(buffer,"\r\n");
     strcat(buffer,"Connection: close\r\n\r\n");
     if(req==1)
       {
         fread(buf2,1,fstat.st_size,file);
         strcat(buffer,buf2);
       }
     fclose(file);
    }
   }
   printf("Server response:\n%s\n",buffer);
   send(clientfd, buffer, 2048, 0);
   if ( close(clientfd) < 0 ) {
    perror("Error closing client connection.");
    exit((*__errno_location ()));
   }
   exit(0);
  }
  if ( close(clientfd) < 0 ) {
   perror("Error closing client connection in parent.");
   exit((*__errno_location ()));
  }
  waitpid(-1, ((void *)0), 1);
 }
 return 0;
}

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

variable_types:
buffer
char [2048]

variable_types: pid int

variable_types: clientfd int

variable_types:
clientlen
unsigned int

variable_types:
type
char *

variable_types: req int

variable_types:
res
char *

variable_types:
version
char *

variable_types:
line
char *

variable_types:
directory
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: rawtime long

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

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

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

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


argcmpTestOptions

repo: tychon/chaospendel

decompiled_code:
__int64 __fastcall argcmpTestOptions(char *s2, char *a2)
{
int v4; // eax
char *v5; // rdi
char *save_ptr; // [rsp+8h] [rbp-10h] BYREF

save_ptr = (char *)&unk_30F;
do
{
v5 = strtok_r(a2, "|", &save_ptr);
if ( !v5 )
return 0LL;
v4 = strcmp(v5, s2);
a2 = 0LL;
}
while ( v4 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2, char *a2)
{
int v4; // eax
char *v5; // rdi
char *save_ptr; // [rsp+8h] [rbp-10h] BYREF

save_ptr = (char *)&unk_30F;
do
{
v5 = strtok_r(a2, "|", &save_ptr);
if ( !v5 )
return 0LL;
v4 = strcmp(v5, s2);
a2 = 0LL;
}
while ( v4 );
return 1LL;
}

original_code:
int argcmpTestOptions(const char *arg, char *options) {
  char *token = "x", *saveptr = "y";
  while ( (token = strtok_r(options, "|", &saveptr)) ) {
    options = ((void *)0);
    if (strcmp(token, arg) == 0) return 1;
  }
  return 0;
}

canonical_original_code:
int argcmpTestOptions(char *arg, char *options) {
  char *token = "x"; char *saveptr = "y";
  while ( (token = strtok_r(options, "|", &saveptr)) ) {
    options = ((void *)0);
    if (strcmp(token, arg) == 0) return 1;
  }
  return 0;
}

variable_types:
arg
char *

variable_types:
options
char *

variable_types:
token
char *

variable_types:
saveptr
char *


getMicroseconds

decompiled_code:
__suseconds_t getMicroseconds()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func1()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
long long getMicroseconds() {
  struct timeval tv;
  gettimeofday(&tv, ((void *)0));
  return (long long)tv.tv_sec * 1000000 + tv.tv_usec;
}

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

return_type: long long


argcmpass

decompiled_code:
__int64 __fastcall argcmpass(char *src, int a2, __int64 a3, int *a4, _QWORD *a5)
{
size_t v8; // rax
char *v9; // rax
char *v10; // rax
__int64 result; // rax
int v12; // eax

v8 = strlen(src);
v9 = (char *)assert_malloc(v8 + 1);
v10 = strcpy(v9, src);
result = argcmpTestOptions(*(char **)(a3 + 8LL * *a4), v10);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v12 = *a4 + 1;
*a4 = v12;
if ( !strcmp("NULL", *(const char **)(a3 + 8LL * v12)) )
{
result = 1LL;
*a5 = 0LL;
}
else
{
*a5 = *(_QWORD *)(a3 + 8LL * v12);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int a2, __int64 a3, int *a4, _QWORD *a5)
{
size_t v8; // rax
char *v9; // rax
char *v10; // rax
__int64 result; // rax
int v12; // eax

v8 = strlen(src);
v9 = (char *)assert_malloc(v8 + 1);
v10 = strcpy(v9, src);
result = func0(*(char **)(a3 + 8LL * *a4), v10);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
exit(1);
}
v12 = *a4 + 1;
*a4 = v12;
if ( !strcmp("NULL", *(const char **)(a3 + 8LL * v12)) )
{
result = 1LL;
*a5 = 0LL;
}
else
{
*a5 = *(_QWORD *)(a3 + 8LL * v12);
result = 1LL;
}
}
return result;
}

original_code:
int argcmpass(char *options, const int argc, char *argv[], int *argindex, char **dest) {
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(argv[*argindex], opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    if (strcmp("NULL", argv[*argindex]) != 0)
      *dest = argv[*argindex];
    else *dest = ((void *)0);
    return 1;
  }
  else
    return 0;
}

canonical_original_code:
int argcmpass(char *options, int argc, char *argv[], int *argindex, char **dest) {
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(argv[*argindex], opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    if (strcmp("NULL", argv[*argindex]) != 0)
      *dest = argv[*argindex];
    else *dest = ((void *)0);
    return 1;
  }
  else
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
argindex
int *

variable_types:
dest
char **

variable_types:
opts
char *


argcmpassint

decompiled_code:
__int64 __fastcall argcmpassint(char *src, int a2, __int64 a3, int *a4, _DWORD *a5)
{
char *v8; // r13
size_t v9; // rax
char *v10; // rax
char *v11; // rax
__int64 result; // rax
int v13; // eax
const char *v14; // rbx
__int64 v15; // rax
char *endptr; // [rsp+8h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
v11 = strcpy(v10, src);
result = argcmpTestOptions(v8, v11);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
}
else
{
v13 = *a4 + 1;
*a4 = v13;
v14 = *(const char **)(a3 + 8LL * v13);
v15 = strtol(v14, &endptr, 0);
if ( v15 < (__int64)0xFFFFFFFF80000000LL )
{
fprintf(stderr, "error: Value of option \"%s\" is too small.\n", v8);
}
else if ( v15 == 0x7FFFFFFFFFFFFFFFLL )
{
fprintf(stderr, "error: Value of option \"%s\" is too big.\n", v8);
}
else
{
if ( endptr != v14 )
{
*a5 = v15;
return 1LL;
}
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
}
}
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, int a2, __int64 a3, int *a4, _DWORD *a5)
{
char *v8; // r13
size_t v9; // rax
char *v10; // rax
char *v11; // rax
__int64 result; // rax
int v13; // eax
const char *v14; // rbx
__int64 v15; // rax
char *endptr; // [rsp+8h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
v11 = strcpy(v10, src);
result = func0(v8, v11);
if ( (_DWORD)result )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
}
else
{
v13 = *a4 + 1;
*a4 = v13;
v14 = *(const char **)(a3 + 8LL * v13);
v15 = strtol(v14, &endptr, 0);
if ( v15 < (__int64)0xFFFFFFFF80000000LL )
{
fprintf(stderr, "error: Value of option \"%s\" is too small.\n", v8);
}
else if ( v15 == 0x7FFFFFFFFFFFFFFFLL )
{
fprintf(stderr, "error: Value of option \"%s\" is too big.\n", v8);
}
else
{
if ( endptr != v14 )
{
*a5 = v15;
return 1LL;
}
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
}
}
exit(1);
}
return result;
}

original_code:
int argcmpassint(char *options, const int argc, char *argv[], int *argindex, int *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr, *value = argv[*argindex];
    long parsed = strtol(value, &endptr, 0);
    if (parsed < (-0x7fffffff - 1)) {
      fprintf(stderr, "error: Value of option \"%s\" is too small.\n", opt);
      exit(1);
    } else if (parsed == 0x7fffffffffffffffL) {
      fprintf(stderr, "error: Value of option \"%s\" is too big.\n", opt);
      exit(1);
    } else if (value == endptr) {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = (int)parsed;
    return 1;
  }
  else
    return 0;
}

canonical_original_code:
int argcmpassint(char *options, int argc, char *argv[], int *argindex, int *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr; char *value = argv[*argindex];
    long parsed = strtol(value, &endptr, 0);
    if (parsed < (-0x7fffffff - 1)) {
      fprintf(stderr, "error: Value of option \"%s\" is too small.\n", opt);
      exit(1);
    } else if (parsed == 0x7fffffffffffffffL) {
      fprintf(stderr, "error: Value of option \"%s\" is too big.\n", opt);
      exit(1);
    } else if (value == endptr) {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = (int)parsed;
    return 1;
  }
  else
    return 0;
}

variable_types:
dest
int *

variable_types:
opt
char *

variable_types:
endptr
char *

variable_types:
value
char *

variable_types: parsed long


argcmpassdouble

decompiled_code:
double __fastcall argcmpassdouble(char *src, int a2, __int64 a3, int *a4, double *a5)
{
char *v8; // r12
size_t v9; // rax
char *v10; // rax
char *v11; // rax
int v12; // eax
const char *v13; // rbx
double v14; // xmm0_8
char *endptr; // [rsp+8h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
v11 = strcpy(v10, src);
if ( (unsigned int)argcmpTestOptions(v8, v11) )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
}
else
{
v12 = *a4 + 1;
*a4 = v12;
v13 = *(const char **)(a3 + 8LL * v12);
v14 = strtod(v13, &endptr);
if ( endptr != v13 && !*endptr )
{
*a5 = v14;
return *(double *)&LC7;
}
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
}
exit(1);
}
return 0.0;
}

canonical_decompiled_code:
double __fastcall func4(char *src, int a2, __int64 a3, int *a4, double *a5)
{
char *v8; // r12
size_t v9; // rax
char *v10; // rax
char *v11; // rax
int v12; // eax
const char *v13; // rbx
double v14; // xmm0_8
char *endptr; // [rsp+8h] [rbp-40h] BYREF

v8 = *(char **)(a3 + 8LL * *a4);
v9 = strlen(src);
v10 = (char *)assert_malloc(v9 + 1);
v11 = strcpy(v10, src);
if ( (unsigned int)func0(v8, v11) )
{
if ( *a4 >= a2 - 1 )
{
fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", src);
}
else
{
v12 = *a4 + 1;
*a4 = v12;
v13 = *(const char **)(a3 + 8LL * v12);
v14 = strtod(v13, &endptr);
if ( endptr != v13 && !*endptr )
{
*a5 = v14;
return *(double *)&LC7;
}
fprintf(stderr, "error: Invalid number in option \"%s\".\n", v8);
}
exit(1);
}
return 0.0;
}

original_code:
double argcmpassdouble(char *options, const int argc, char *argv[], int *argindex, double *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr, *value = argv[*argindex];
    double parsed = strtod(value, &endptr);
    if (value == endptr || *endptr != '\0') {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = parsed;
    return 1;
  }
  else
    return 0;
}

canonical_original_code:
double argcmpassdouble(char *options, int argc, char *argv[], int *argindex, double *dest) {
  char *opt = argv[*argindex];
  char *opts = assert_malloc(strlen(options)+1);
  strcpy(opts, options);
  if (argcmpTestOptions(opt, opts)) {
    if (*argindex >= argc-1) {
      fprintf(stderr, "error: Invalid argument, expected value after option \"%s\"\n", options);
      exit(1);
    }
    (*argindex) ++;
    char *endptr; char *value = argv[*argindex];
    double parsed = strtod(value, &endptr);
    if (value == endptr || *endptr != '\0') {
      fprintf(stderr, "error: Invalid number in option \"%s\".\n", opt);
      exit(1);
    } else
      *dest = parsed;
    return 1;
  }
  else
    return 0;
}

variable_types:
dest
double *

variable_types: parsed double

return_type: double


decompiled_code:
void *__fastcall assert_calloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( a2 != 0 && a1 != 0 && !result )
_assert_fail("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9u, "assert_calloc");
return result;
}

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

result = calloc(a1, a2);
if ( a2 != 0 && a1 != 0 && !result )
_assert_fail("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9u, "assert_calloc");
return result;
}

original_code:
void *assert_calloc(size_t nmemb, size_t size) {
  void *result = calloc(nmemb, size);
  ((void) sizeof ((result != ((void *)0) || nmemb == 0 || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || nmemb == 0 || size == 0) ; else __assert_fail ("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

canonical_original_code:
void *assert_calloc(unsigned long nmemb, unsigned long size) {
  void *result = calloc(nmemb, size);
  ((void) sizeof ((result != ((void *)0) || nmemb == 0 || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || nmemb == 0 || size == 0) ; else __assert_fail ("result != NULL || nmemb == 0 || size == 0", "memory_wrappers.c", 9, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

variable_types:
result
void *

return_type: void *


decompiled_code:
void *__fastcall assert_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0xFu, "assert_malloc");
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a1 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0xFu, "assert_malloc");
}
return result;
}

original_code:
void *assert_malloc(size_t size) {
  void *result = malloc(size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

canonical_original_code:
void *assert_malloc(unsigned long size) {
  void *result = malloc(size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 15, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}


decompiled_code:
void *__fastcall assert_realloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0x15u, "assert_realloc");
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
_assert_fail("result != NULL || size == 0", "memory_wrappers.c", 0x15u, "assert_realloc");
}
return result;
}

original_code:
void *assert_realloc(void *ptr, size_t size) {
  void *result = realloc(ptr, size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 21, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

canonical_original_code:
void *assert_realloc(void *ptr, unsigned long size) {
  void *result = realloc(ptr, size);
  ((void) sizeof ((result != ((void *)0) || size == 0) ? 1 : 0), __extension__ ({ if (result != ((void *)0) || size == 0) ; else __assert_fail ("result != NULL || size == 0", "memory_wrappers.c", 21, __extension__ __PRETTY_FUNCTION__); }));
  return result;
}

variable_types:
ptr
void *


repo: tyler-cromwell/Strutil

original_code:
char * strutil_lcs(char *str1, char *str2) {
    size_t m = strlen(str1);
    size_t n = strlen(str2);
    size_t l = 0;
    char *B = calloc(m * n, sizeof(char));
    char *C = calloc(m * n, sizeof(char));
    char *lcs = ((void *)0);
    for (size_t i = 1; i < m; i++) {
        for (size_t j = 1; j < n; j++) {
            if (str1[i] == str2[j]) {
                C[i*n+j] = C[(i-1)*n+(j-1)] + 1;
                B[i*n+j] = DIAGONAL;
            }
            else if (C[(i-1)*n+j] >= C[i*n+(j-1)]) {
                C[i*n+j] = C[(i-1)*n+j];
                B[i*n+j] = UP;
            }
            else {
                C[i*n+j] = C[i*n+(j-1)];
                B[i*n+j] = LEFT;
            }
        }
    }
    size_t i = m-1;
    size_t j = n-1;
    while (i != 0 && j != 0) {
        if (B[i*n+j] == DIAGONAL) {
            i--;
            j--;
            lcs = realloc(lcs, (l+1) * sizeof(char));
            lcs[l++] = str1[i+1];
        }
        else if (B[i*n+j] == UP) {
            i--;
        }
        else {
            j--;
        }
    }
    lcs = realloc(lcs, (l+1) * sizeof(char));
    lcs[l] = '\0';
    char *result = strutil_reverse(lcs);
    free(B);
    free(C);
    free(lcs);
    return result;
}

canonical_original_code:
char *strutil_lcs(char *str1, char *str2) {
    unsigned long m = strlen(str1);
    unsigned long n = strlen(str2);
    unsigned long l = 0;
    char *B = calloc(m * n, sizeof(char));
    char *C = calloc(m * n, sizeof(char));
    char *lcs = ((void *)0);
    for (unsigned long i = 1; i < m; i++) {
        for (unsigned long j = 1; j < n; j++) {
            if (str1[i] == str2[j]) {
                C[i*n+j] = C[(i-1)*n+(j-1)] + 1;
                B[i*n+j] = DIAGONAL;
            }
            else if (C[(i-1)*n+j] >= C[i*n+(j-1)]) {
                C[i*n+j] = C[(i-1)*n+j];
                B[i*n+j] = UP;
            }
            else {
                C[i*n+j] = C[i*n+(j-1)];
                B[i*n+j] = LEFT;
            }
        }
    }
    unsigned long i = m-1;
    unsigned long j = n-1;
    while (i != 0 && j != 0) {
        if (B[i*n+j] == DIAGONAL) {
            i--;
            j--;
            lcs = realloc(lcs, (l+1) * sizeof(char));
            lcs[l++] = str1[i+1];
        }
        else if (B[i*n+j] == UP) {
            i--;
        }
        else {
            j--;
        }
    }
    lcs = realloc(lcs, (l+1) * sizeof(char));
    lcs[l] = '\0';
    char *result = strutil_reverse(lcs);
    free(B);
    free(C);
    free(lcs);
    return result;
}

variable_types:
m
unsigned long

variable_types:
n
unsigned long

variable_types:
l
unsigned long

variable_types:
B
char *

variable_types:
C
char *

variable_types:
lcs
char *

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
result
char *


decompiled_code:
char *__fastcall strutil_reverse(char *src)
{
size_t v1; // rbx
char *v2; // rax
char *v3; // rax
char *v4; // r8
char *v5; // rdx
char *v6; // rdi
char v7; // si
char v8; // cl

v1 = strlen(src);
v2 = (char *)calloc(v1 + 1, 1uLL);
v3 = strncpy(v2, src, v1);
v4 = v3;
if ( v1 >> 1 )
{
v5 = &v3[v1 - 1];
v6 = &v3[v1 >> 1];
do
{
v7 = *v5;
v8 = *v3++;
--v5;
*(v3 - 1) = v7;
v5[1] = v8;
}
while ( v3 != v6 );
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func14(char *src)
{
size_t v1; // rbx
char *v2; // rax
char *v3; // rax
char *v4; // r8
char *v5; // rdx
char *v6; // rdi
char v7; // si
char v8; // cl

v1 = strlen(src);
v2 = (char *)calloc(v1 + 1, 1uLL);
v3 = strncpy(v2, src, v1);
v4 = v3;
if ( v1 >> 1 )
{
v5 = &v3[v1 - 1];
v6 = &v3[v1 >> 1];
do
{
v7 = *v5;
v8 = *v3++;
--v5;
*(v3 - 1) = v7;
v5[1] = v8;
}
while ( v3 != v6 );
}
return v4;
}

original_code:
char * strutil_reverse(char *string) {
    char temp = 0;
    size_t length = strlen(string);
    char *reversed = calloc(length + 1, sizeof(char));
    strncpy(reversed, string, length);
    for (size_t i = 0; i < (length / 2); i++) {
        temp = reversed[i];
        reversed[i] = reversed[length-1-i];
        reversed[length-1-i] = temp;
    }
    return reversed;
}

canonical_original_code:
char *strutil_reverse(char *string) {
    char temp = 0;
    unsigned long length = strlen(string);
    char *reversed = calloc(length + 1, sizeof(char));
    strncpy(reversed, string, length);
    for (unsigned long i = 0; i < (length / 2); i++) {
        temp = reversed[i];
        reversed[i] = reversed[length-1-i];
        reversed[length-1-i] = temp;
    }
    return reversed;
}

variable_types:
string
char *

variable_types: temp char

variable_types:
length
unsigned long

variable_types:
reversed
char *


decompiled_code:
__int64 __fastcall strutil_ends_with(char *s, char *s2)
{
size_t v2; // rbx
size_t v3; // rax
__int64 result; // rax
void *v5; // r13
size_t v6; // rax

mcount(s, s2);
v2 = strlen(s2);
v3 = strlen(s);
if ( v2 > v3 )
return 0LL;
v5 = (void *)strutil_substring(s, v3 - v2, v3);
v6 = strlen(s2);
if ( !strncmp((const char *)v5, s2, v6) )
{
free(v5);
result = 1LL;
}
else
{
free(v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s, char *s2)
{
size_t v2; // rbx
size_t v3; // rax
__int64 result; // rax
void *v5; // r13
size_t v6; // rax

func1(s, s2);
v2 = strlen(s2);
v3 = strlen(s);
if ( v2 > v3 )
return 0LL;
v5 = (void *)func9(s, v3 - v2, v3);
v6 = strlen(s2);
if ( !strncmp((const char *)v5, s2, v6) )
{
free(v5);
result = 1LL;
}
else
{
free(v5);
result = 0LL;
}
return result;
}

original_code:
int strutil_ends_with(char *string, char *endtok) {
    if (strlen(endtok) > strlen(string)) {
        return 0;
    }
    char *substr = strutil_substring(string, strlen(string)-strlen(endtok), strlen(string));
    if (!strncmp(substr, endtok, strlen(endtok))) {
        free(substr);
        return 1;
    } else {
        free(substr);
        return 0;
    }
}

variable_types:
endtok
char *

variable_types:
substr
char *


decompiled_code:
char *__fastcall strutil_substring(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
size_t v3; // r12
char *v4; // rax

mcount(a1, a2);
v3 = v2 - a2;
v4 = (char *)calloc(v2 - a2 + 1, 1uLL);
return strncpy(v4, (const char *)(a1 + a2), v3);
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
size_t v3; // r12
char *v4; // rax

func1(a1, a2);
v3 = v2 - a2;
v4 = (char *)calloc(v2 - a2 + 1, 1uLL);
return strncpy(v4, (const char *)(a1 + a2), v3);
}

original_code:
char * strutil_substring(char *original, size_t start, size_t end) {
    char *substring = calloc((end-start)+1, sizeof(char));
    strncpy(substring, original+start, end-start);
    return substring;
}

canonical_original_code:
char *strutil_substring(char *original, unsigned long start, unsigned long end) {
    char *substring = calloc((end-start)+1, sizeof(char));
    strncpy(substring, original+start, end-start);
    return substring;
}

variable_types:
original
char *

variable_types:
start
unsigned long

variable_types:
end
unsigned long

variable_types:
substring
char *


decompiled_code:
__int64 __fastcall strutil_contains(char *s1, char *s2)
{
char *v2; // rbx
size_t v3; // r14
size_t v4; // rax
unsigned int v5; // er8
char *v6; // r12

mcount(s1, s2);
v2 = s1;
v3 = strlen(s2);
v4 = strlen(s1);
v5 = 0;
if ( v3 > v4 || !v4 )
return v5;
v6 = &s1[v4];
do
{
if ( !strncmp(v2, s2, v3) )
return 1;
++v2;
}
while ( v6 != v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s1, char *s2)
{
char *v2; // rbx
size_t v3; // r14
size_t v4; // rax
unsigned int v5; // er8
char *v6; // r12

func1(s1, s2);
v2 = s1;
v3 = strlen(s2);
v4 = strlen(s1);
v5 = 0;
if ( v3 > v4 || !v4 )
return v5;
v6 = &s1[v4];
do
{
if ( !strncmp(v2, s2, v3) )
return 1;
++v2;
}
while ( v6 != v2 );
return 0LL;
}

original_code:
int strutil_contains(char *string, char *sequence) {
    char *s = string;
    if (strlen(sequence) > strlen(string)) {
        return 0;
    }
    for (size_t i = 0; i < strlen(string); i++) {
        if (!strncmp(s, sequence, strlen(sequence))) {
            return 1;
        } else {
            s++;
        }
    }
    return 0;
}

canonical_original_code:
int strutil_contains(char *string, char *sequence) {
    char *s = string;
    if (strlen(sequence) > strlen(string)) {
        return 0;
    }
    for (unsigned long i = 0; i < strlen(string); i++) {
        if (!strncmp(s, sequence, strlen(sequence))) {
            return 1;
        } else {
            s++;
        }
    }
    return 0;
}

variable_types:
sequence
char *

variable_types:
s
char *


decompiled_code:
char *__fastcall strutil_trim(char *src)
{
char *v1; // r12
size_t v2; // rcx
__int64 i; // rax
size_t j; // rdx
size_t v5; // rbx
char *v6; // rax

mcount(src);
if ( !src )
return 0LL;
v1 = src;
v2 = strlen(src);
for ( i = 0LL; *v1 == 32; ++i )
{
if ( i == v2 )
break;
++v1;
}
for ( j = v2 - 1; src[j] == 32; --j )
{
if ( !j )
break;
}
v5 = j - i;
v6 = (char *)calloc(j - i + 2, 1uLL);
return strncpy(v6, v1, v5 + 1);
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
char *v1; // r12
size_t v2; // rcx
__int64 i; // rax
size_t j; // rdx
size_t v5; // rbx
char *v6; // rax

func1(src);
if ( !src )
return 0LL;
v1 = src;
v2 = strlen(src);
for ( i = 0LL; *v1 == 32; ++i )
{
if ( i == v2 )
break;
++v1;
}
for ( j = v2 - 1; src[j] == 32; --j )
{
if ( !j )
break;
}
v5 = j - i;
v6 = (char *)calloc(j - i + 2, 1uLL);
return strncpy(v6, v1, v5 + 1);
}

original_code:
char *strutil_trim(char *original) {
    if (original != ((void *)0)) {
        size_t i = 0;
        while (original[i] == ' ' && i < strlen(original)) i++;
        size_t start = i;
        for (i = strlen(original)-1; original[i] == ' ' && i > 0; i--);
        size_t end = i;
        char *new = calloc(end-start+2, sizeof(char));
        strncpy(new, original+start, end-start+1);
        return new;
    }
    else {
        return ((void *)0);
    }
}

canonical_original_code:
char *strutil_trim(char *original) {
    if (original != ((void *)0)) {
        unsigned long i = 0;
        while (original[i] == ' ' && i < strlen(original)) i++;
        unsigned long start = i;
        for (i = strlen(original)-1; original[i] == ' ' && i > 0; i--);
        unsigned long end = i;
        char *new = calloc(end-start+2, sizeof(char));
        strncpy(new, original+start, end-start+1);
        return new;
    }
    else {
        return ((void *)0);
    }
}

variable_types:
new
char *


decompiled_code:
char *__fastcall strutil_replace_all(char *src, char a2)
{
char v2; // dl
char v3; // bl
size_t v4; // r14
__int64 *v5; // r15
char *v6; // r12
__int64 *v7; // rax
__int64 *v8; // rcx
__int64 v9; // rdx
__int64 v11[7]; // [rsp+8h] [rbp-38h] BYREF

mcount(src);
v3 = v2;
v11[0] = 0LL;
v4 = strlen(src);
v5 = (__int64 *)strutil_indices_of(src, (unsigned int)a2, v11);
v6 = (char *)calloc(v4 + 1, 1uLL);
strncpy(v6, src, v4);
if ( v11[0] )
{
v7 = v5;
v8 = &v5[v11[0]];
do
{
v9 = *v7++;
v6[v9] = v3;
}
while ( v8 != v7 );
}
free(v5);
return v6;
}

original_code:
char * strutil_replace_all(char *string, char old, char new) {
    size_t amount = 0;
    size_t length = strlen(string);
    size_t *indices = strutil_indices_of(string, old, &amount);
    char *replaced = calloc(length + 1, sizeof(char));
    strncpy(replaced, string, length);
    for (size_t i = 0; i < amount; i++) {
        replaced[indices[i]] = new;
    }
    free(indices);
    return replaced;
}

canonical_original_code:
char *strutil_replace_all(char *string, char old, char new) {
    unsigned long amount = 0;
    unsigned long length = strlen(string);
    unsigned long *indices = strutil_indices_of(string, old, &amount);
    char *replaced = calloc(length + 1, sizeof(char));
    strncpy(replaced, string, length);
    for (unsigned long i = 0; i < amount; i++) {
        replaced[indices[i]] = new;
    }
    free(indices);
    return replaced;
}

variable_types: old char

variable_types: new char

variable_types:
amount
unsigned long

variable_types:
indices
unsigned long *

variable_types:
replaced
char *


decompiled_code:
char *__fastcall strutil_remove(char *src, size_t n)
{
__int64 v2; // rdx
__int64 v3; // r13
size_t v4; // r12
char *v5; // rax
char *v6; // rax

mcount(src, n);
v3 = v2;
v4 = strlen(src);
v5 = (char *)calloc(n - v3 + v4 + 1, 1uLL);
v6 = strncpy(v5, src, n);
return strncat(v6, &src[v3], v4 - v3);
}

canonical_decompiled_code:
char *__fastcall func8(char *src, size_t n)
{
__int64 v2; // rdx
__int64 v3; // r13
size_t v4; // r12
char *v5; // rax
char *v6; // rax

func1(src, n);
v3 = v2;
v4 = strlen(src);
v5 = (char *)calloc(n - v3 + v4 + 1, 1uLL);
v6 = strncpy(v5, src, n);
return strncat(v6, &src[v3], v4 - v3);
}

original_code:
char * strutil_remove(char *original, size_t start, size_t end) {
    size_t len = end - start;
    size_t length = strlen(original);
    char *condensed = calloc(length-len+1, sizeof(char));
    strncpy(condensed, original, start);
    strncat(condensed, original + end, length - end);
    return condensed;
}

canonical_original_code:
char *strutil_remove(char *original, unsigned long start, unsigned long end) {
    unsigned long len = end - start;
    unsigned long length = strlen(original);
    char *condensed = calloc(length-len+1, sizeof(char));
    strncpy(condensed, original, start);
    strncat(condensed, original + end, length - end);
    return condensed;
}

variable_types:
len
unsigned long

variable_types:
condensed
char *


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

mcount();
if ( !*a1 || *a1 == a2 )
return 0LL;
result = 0LL;
do
v3 = a1[++result];
while ( v3 && v3 != a2 );
return result;
}

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

func1();
if ( !*a1 || *a1 == a2 )
return 0LL;
result = 0LL;
do
v3 = a1[++result];
while ( v3 && v3 != a2 );
return result;
}

original_code:
inline size_t strutil_index_of(char *string, char character) {
    size_t i = 0;
    while (string[i] != character && string[i] != '\0') i++;
    return i;
}

canonical_original_code:
inline unsigned long strutil_index_of(char *string, char character) {
    unsigned long i = 0;
    while (string[i] != character && string[i] != '\0') i++;
    return i;
}

variable_types:
string
char *

variable_types: character char

variable_types:
i
unsigned long


decompiled_code:
char *__fastcall strutil_insert(char *src, char *a2)
{
size_t v2; // rdx
size_t v3; // rbx
size_t v4; // rax
char *v5; // r8
size_t v6; // r12
size_t v7; // r15
char *v8; // rax
char *v9; // rax
char *v11; // rax
char *v12; // rax

mcount(src, a2);
v3 = v2;
v4 = strlen(src);
v5 = 0LL;
v6 = v4;
if ( v4 > v3 )
{
v7 = strlen(a2);
v8 = (char *)calloc(v6 + v7, 1uLL);
if ( v3 )
{
v11 = strncpy(v8, src, v3);
v12 = strncat(v11, a2, v7);
v5 = strncat(v12, &src[v3], v6 - v3);
}
else
{
v9 = strncpy(v8, a2, v7);
v5 = strncat(v9, src, v6);
}
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func8(char *src, char *a2)
{
size_t v2; // rdx
size_t v3; // rbx
size_t v4; // rax
char *v5; // r8
size_t v6; // r12
size_t v7; // r15
char *v8; // rax
char *v9; // rax
char *v11; // rax
char *v12; // rax

func1(src, a2);
v3 = v2;
v4 = strlen(src);
v5 = 0LL;
v6 = v4;
if ( v4 > v3 )
{
v7 = strlen(a2);
v8 = (char *)calloc(v6 + v7, 1uLL);
if ( v3 )
{
v11 = strncpy(v8, src, v3);
v12 = strncat(v11, a2, v7);
v5 = strncat(v12, &src[v3], v6 - v3);
}
else
{
v9 = strncpy(v8, a2, v7);
v5 = strncat(v9, src, v6);
}
}
return v5;
}

original_code:
char * strutil_insert(char *original, char *additional, size_t index) {
    size_t lo = strlen(original);
    size_t la = strlen(additional);
    if (index >= lo) {
        return ((void *)0);
    }
    char *expanded = calloc(lo + la, sizeof(char));
    if (index == 0) {
        strncpy(expanded, additional, la);
        strncat(expanded, original, lo);
    } else {
        strncpy(expanded, original, index);
        strncat(expanded, additional, la);
        strncat(expanded, original + index, lo - index);
    }
    return expanded;
}

canonical_original_code:
char *strutil_insert(char *original, char *additional, unsigned long index) {
    unsigned long lo = strlen(original);
    unsigned long la = strlen(additional);
    if (index >= lo) {
        return ((void *)0);
    }
    char *expanded = calloc(lo + la, sizeof(char));
    if (index == 0) {
        strncpy(expanded, additional, la);
        strncat(expanded, original, lo);
    } else {
        strncpy(expanded, original, index);
        strncat(expanded, additional, la);
        strncat(expanded, original + index, lo - index);
    }
    return expanded;
}

variable_types:
original
char *

variable_types:
additional
char *

variable_types:
index
unsigned long

variable_types:
lo
unsigned long

variable_types:
la
unsigned long

variable_types:
expanded
char *


display

repo: tylerschloesser/cgbemu-core

decompiled_code:
__int64 display()
{
glClear(0x4000LL);
glColor3f(1.0, 1.0);
cgbemu_run_to_vblank();
glLoadIdentity();
glTranslatef(0.0, 0.0);
glTexImage2D(3553LL, 0LL, 6407LL, 160LL, 144LL, 0LL, 6407LL, 33635LL, screen_buffer);
glTexParameteri(3553LL, 10240LL, 9728LL);
glBegin(7LL);
glTexCoord2f(0.0, 1.0);
glVertex2f(-1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 1.0);
glVertex2f(1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 0.0);
glVertex2f(1.0);
glTexCoord2f(0.0, 0.0);
glVertex2f(-1.0);
glEnd(-1.0, 1.0);
return glFlush();
}

canonical_decompiled_code:
__int64 func0()
{
glClear(0x4000LL);
glColor3f(1.0, 1.0);
cgbemu_run_to_vblank();
glLoadIdentity();
glTranslatef(0.0, 0.0);
glTexImage2D(3553LL, 0LL, 6407LL, 160LL, 144LL, 0LL, 6407LL, 33635LL, screen_buffer);
glTexParameteri(3553LL, 10240LL, 9728LL);
glBegin(7LL);
glTexCoord2f(0.0, 1.0);
glVertex2f(-1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 1.0);
glVertex2f(1.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 0.0);
glVertex2f(1.0);
glTexCoord2f(0.0, 0.0);
glVertex2f(-1.0);
glEnd(-1.0, 1.0);
return glFlush();
}

original_code:
void display(void)
{
    glClear (0x00004000);
    glColor3f (1.0, 1.0, 1.0);
    cgbemu_run_to_vblank();
    glLoadIdentity();
    glTranslatef( 0, 0, 0.f );
    glTexImage2D(0x0DE1,
        0,
        0x1907,
        160,
        144,
        0,
        0x1907,
        0x8363,
        screen_buffer);
    glTexParameteri(0x0DE1, 0x2800, 0x2600);
    glBegin (0x0007);
    glTexCoord2f (0.0, 1.0); glVertex2f (-1.0, -1.0);
    glTexCoord2f (1.0, 1.0); glVertex2f (1.0, -1.0);
    glTexCoord2f (1.0, 0.0); glVertex2f (1.0, 1.0);
    glTexCoord2f (0.0, 0.0); glVertex2f (-1.0, 1.0);
    glEnd ();
    glFlush ();
}

canonical_original_code:
void display()
{
    glClear (0x00004000);
    glColor3f (1.0, 1.0, 1.0);
    cgbemu_run_to_vblank();
    glLoadIdentity();
    glTranslatef( 0, 0, 0.f );
    glTexImage2D(0x0DE1,
        0,
        0x1907,
        160,
        144,
        0,
        0x1907,
        0x8363,
        screen_buffer);
    glTexParameteri(0x0DE1, 0x2800, 0x2600);
    glBegin (0x0007);
    glTexCoord2f (0.0, 1.0); glVertex2f (-1.0, -1.0);
    glTexCoord2f (1.0, 1.0); glVertex2f (1.0, -1.0);
    glTexCoord2f (1.0, 0.0); glVertex2f (1.0, 1.0);
    glTexCoord2f (0.0, 0.0); glVertex2f (-1.0, 1.0);
    glEnd ();
    glFlush ();
}


reshape

decompiled_code:
__int64 __fastcall reshape(unsigned int a1, unsigned int a2)
{
window_height = a2;
window_width = a1;
glViewport(0LL, 0LL, a1, a2);
glDeleteTextures(1LL, &texture);
glEnable(3553LL);
glGenTextures(1LL, &texture);
glBindTexture(3553LL, (unsigned int)texture);
glTexParameterf(3553LL, 10241LL, 9729.0);
return glTexParameterf(3553LL, 10240LL, 9729.0);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
window_height = a2;
window_width = a1;
glViewport(0LL, 0LL, a1, a2);
glDeleteTextures(1LL, &texture);
glEnable(3553LL);
glGenTextures(1LL, &texture);
glBindTexture(3553LL, (unsigned int)texture);
glTexParameterf(3553LL, 10241LL, 9729.0);
return glTexParameterf(3553LL, 10240LL, 9729.0);
}

original_code:
void reshape (int w, int h)
{
    window_height = h;
    window_width = w;
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glDeleteTextures(1, &texture);
    glEnable(0x0DE1);
    glGenTextures(1, &texture);
    glBindTexture(0x0DE1, texture);
    glTexParameterf(0x0DE1, 0x2801, 0x2601);
    glTexParameterf(0x0DE1, 0x2800, 0x2601);
}

canonical_original_code:
void reshape(int w, int h)
{
    window_height = h;
    window_width = w;
    glViewport (0, 0, (int) w, (int) h);
    glDeleteTextures(1, &texture);
    glEnable(0x0DE1);
    glGenTextures(1, &texture);
    glBindTexture(0x0DE1, texture);
    glTexParameterf(0x0DE1, 0x2801, 0x2601);
    glTexParameterf(0x0DE1, 0x2800, 0x2601);
}

variable_types: w int

variable_types: h int


decompiled_code:
__int64 save_state_callback()
{
return cgbemu_save_state("save_state.bin");
}

canonical_decompiled_code:
__int64 func2()
{
return cgbemu_save_state("save_state.bin");
}

original_code:
void save_state_callback() {
    cgbemu_save_state("save_state.bin");
}


decompiled_code:
__int64 load_state_callback()
{
return cgbemu_load_state("save_state.bin");
}

canonical_decompiled_code:
__int64 func3()
{
return cgbemu_load_state("save_state.bin");
}

original_code:
void load_state_callback() {
    cgbemu_load_state("save_state.bin");
}