decompiled_code:
char *__fastcall deeper_babel_init(char *needle, __int64 a2)
{
char *v2; // r13
char *v3; // rax
char v4; // bl
const __int32_t **v5; // rcx
char *v6; // rax
__int64 (__fastcall *v7)(__int64, _QWORD, _QWORD, char *, __int64); // rax
__int64 v8; // rbx
__int64 (__fastcall *v9)(__int64, _QWORD, _QWORD, _QWORD, _QWORD); // rax
__int64 v10; // rbx
int v11; // er14
int v12; // er12
void (__fastcall *v13)(__int64, _QWORD, _QWORD, char *, __int64); // rax
unsigned int v14; // eax
__int64 v15; // rdi
char *result; // rax
int v17; // edx
int v18; // eax
__int64 (__fastcall *v19)(__int64, _QWORD, _QWORD, char *, __int64); // rax
__int64 v20; // rbx
int v21; // edx
int v22; // edx
__int64 (__fastcall *v23)(__int64, _QWORD, _QWORD, char *, __int64); // rax
__int64 v24; // rbx
__int64 v25; // rax
int v26; // er12
int (__fastcall *v27)(__int64, _QWORD, _QWORD, char *, __int64); // rax
bool v28; // sf
__int64 (__fastcall *v29)(__int64, _QWORD, _QWORD, _QWORD, _QWORD); // rax
__int64 v30; // rbx
int v31; // er13
int v32; // eax
char v33[512]; // [rsp+0h] [rbp-428h] BYREF
char v34[552]; // [rsp+200h] [rbp-228h] BYREF

v2 = needle;
if ( !needle )
goto LABEL_7;
v3 = strrchr(needle, 46);
v2 = v3;
if ( !v3 )
goto LABEL_7;
v4 = *v3;
if ( *v3 )
{
v5 = _ctype_tolower_loc();
v6 = v2;
do
{
*v6++ = (*v5)[v4];
v4 = *v6;
}
while ( *v6 );
}
v7 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))container_registry;
v8 = 1LL;
if ( !container_registry )
goto LABEL_7;
do
{
v12 = v8 - 1;
if ( (int)v7(515LL, 0LL, 0LL, buffer_0, 512LL) >= 0
&& strstr(buffer_0, v2)
&& (int)(*(&container_registry + v8 - 1))(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL) >= 0 )
{
break;
}
v12 = v8++;
v7 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&container_registry + v8 - 1);
}
while ( v7 );
if ( *(&container_registry + v12) )
{
v13 = (void (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&container_registry + v12);
LABEL_15:
*(_QWORD *)a2 = v13;
v13(514LL, 0LL, 0LL, v34, 512LL);
*(_BYTE *)(a2 + 44) = 1;
v14 = (*(&container_registry + v12))(1297LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL);
v15 = v14;
*(_DWORD *)(a2 + 40) = v14;
result = 0LL;
if ( (int)v15 > 0 )
{
*(_QWORD *)(a2 + 32) = my_malloc(v15, "contained story file");
if ( *(int *)(a2 + 40) <= 0 )
{
result = 0LL;
}
else
{
v21 = (*(&container_registry + v12))(1808LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), v33, 512LL);
result = 0LL;
if ( v21 >= 0 )
{
v22 = (*(&container_registry + v12))(
1809LL,
*(_QWORD *)(a2 + 16),
*(unsigned int *)(a2 + 24),
*(_QWORD *)(a2 + 32),
*(unsigned int *)(a2 + 40));
result = 0LL;
if ( v22 > 0 )
{
v23 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))treaty_registry;
if ( treaty_registry )
{
v24 = 0LL;
while ( (int)v23(514LL, 0LL, 0LL, buffer_0, 512LL) < 0
|| strcmp(buffer_0, v33)
|| (int)(*(&treaty_registry + v24))(
260LL,
*(_QWORD *)(a2 + 32),
*(unsigned int *)(a2 + 40),
0LL,
0LL) < 0 )
{
++v24;
v23 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&treaty_registry + v24);
if ( !v23 )
goto LABEL_64;
}
v25 = (__int64)*(&treaty_registry + (int)v24);
if ( v25 )
{
*(_QWORD *)(a2 + 8) = v25;
sprintf(buffer_0, "%sed %s", v34, v33);
result = buffer_0;
}
else
{
result = 0LL;
}
}
else
{
LABEL_64:
result = 0LL;
}
}
}
}
}
}
else
{
LABEL_7:
v9 = container_registry;
if ( container_registry )
{
v10 = 1LL;
v11 = -1;
while ( 1 )
{
v12 = v10 - 1;
v18 = v9(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL);
if ( v18 == 1 )
break;
if ( !v18 && v11 < 0 )
v11 = v10 - 1;
v17 = v10++;
v9 = *(&container_registry + v10 - 1);
if ( !v9 )
{
if ( *(&container_registry + v17) || v11 < 0 )
goto LABEL_27;
goto LABEL_25;
}
}
if ( !*(&container_registry + v12) && v11 >= 0 )
{
LABEL_25:
*(_BYTE *)(a2 + 56) = 0;
v12 = v11;
}
v13 = (void (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&container_registry + v12);
if ( v13 )
goto LABEL_15;
}
LABEL_27:
*(_BYTE *)(a2 + 44) = 0;
if ( !v2 )
goto LABEL_51;
v19 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))treaty_registry;
if ( !treaty_registry )
goto LABEL_51;
v20 = 1LL;
do
{
v26 = v20 - 1;
if ( (int)v19(515LL, 0LL, 0LL, buffer_0, 512LL) >= 0
&& strstr(buffer_0, v2)
&& (int)(*(&treaty_registry + v20 - 1))(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL) >= 0 )
{
break;
}
v26 = v20++;
v19 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&treaty_registry + v20 - 1);
}
while ( v19 );
if ( !*(&treaty_registry + v26) )
{
LABEL_51:
v29 = treaty_registry;
if ( !treaty_registry )
return 0LL;
v30 = 0LL;
v31 = -1;
while ( 1 )
{
v26 = v30;
v32 = v29(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL);
if ( v32 == 1 )
break;
if ( !v32 && v31 < 0 )
v31 = v30;
++v30;
v29 = *(&treaty_registry + v30);
if ( !v29 )
goto LABEL_60;
}
if ( *(&treaty_registry + (int)v30) )
goto LABEL_48;
LABEL_60:
if ( v31 <= 0 )
return 0LL;
*(_BYTE *)(a2 + 56) = 0;
v26 = v31;
}
LABEL_48:
v27 = (int (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&treaty_registry + v26);
*(_QWORD *)a2 = v27;
v28 = v27(514LL, 0LL, 0LL, buffer_0, 512LL) < 0;
result = buffer_0;
if ( v28 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *needle, __int64 a2)
{
char *v2; // r13
char *v3; // rax
char v4; // bl
const __int32_t **v5; // rcx
char *v6; // rax
__int64 (__fastcall *v7)(__int64, _QWORD, _QWORD, char *, __int64); // rax
__int64 v8; // rbx
__int64 (__fastcall *v9)(__int64, _QWORD, _QWORD, _QWORD, _QWORD); // rax
__int64 v10; // rbx
int v11; // er14
int v12; // er12
void (__fastcall *v13)(__int64, _QWORD, _QWORD, char *, __int64); // rax
unsigned int v14; // eax
__int64 v15; // rdi
char *result; // rax
int v17; // edx
int v18; // eax
__int64 (__fastcall *v19)(__int64, _QWORD, _QWORD, char *, __int64); // rax
__int64 v20; // rbx
int v21; // edx
int v22; // edx
__int64 (__fastcall *v23)(__int64, _QWORD, _QWORD, char *, __int64); // rax
__int64 v24; // rbx
__int64 v25; // rax
int v26; // er12
int (__fastcall *v27)(__int64, _QWORD, _QWORD, char *, __int64); // rax
bool v28; // sf
__int64 (__fastcall *v29)(__int64, _QWORD, _QWORD, _QWORD, _QWORD); // rax
__int64 v30; // rbx
int v31; // er13
int v32; // eax
char v33[512]; // [rsp+0h] [rbp-428h] BYREF
char v34[552]; // [rsp+200h] [rbp-228h] BYREF

v2 = needle;
if ( !needle )
goto LABEL_7;
v3 = strrchr(needle, 46);
v2 = v3;
if ( !v3 )
goto LABEL_7;
v4 = *v3;
if ( *v3 )
{
v5 = _ctype_tolower_loc();
v6 = v2;
do
{
*v6++ = (*v5)[v4];
v4 = *v6;
}
while ( *v6 );
}
v7 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))container_registry;
v8 = 1LL;
if ( !container_registry )
goto LABEL_7;
do
{
v12 = v8 - 1;
if ( (int)v7(515LL, 0LL, 0LL, buffer_0, 512LL) >= 0
&& strstr(buffer_0, v2)
&& (int)(*(&container_registry + v8 - 1))(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL) >= 0 )
{
break;
}
v12 = v8++;
v7 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&container_registry + v8 - 1);
}
while ( v7 );
if ( *(&container_registry + v12) )
{
v13 = (void (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&container_registry + v12);
LABEL_15:
*(_QWORD *)a2 = v13;
v13(514LL, 0LL, 0LL, v34, 512LL);
*(_BYTE *)(a2 + 44) = 1;
v14 = (*(&container_registry + v12))(1297LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL);
v15 = v14;
*(_DWORD *)(a2 + 40) = v14;
result = 0LL;
if ( (int)v15 > 0 )
{
*(_QWORD *)(a2 + 32) = my_malloc(v15, "contained story file");
if ( *(int *)(a2 + 40) <= 0 )
{
result = 0LL;
}
else
{
v21 = (*(&container_registry + v12))(1808LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), v33, 512LL);
result = 0LL;
if ( v21 >= 0 )
{
v22 = (*(&container_registry + v12))(
1809LL,
*(_QWORD *)(a2 + 16),
*(unsigned int *)(a2 + 24),
*(_QWORD *)(a2 + 32),
*(unsigned int *)(a2 + 40));
result = 0LL;
if ( v22 > 0 )
{
v23 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))treaty_registry;
if ( treaty_registry )
{
v24 = 0LL;
while ( (int)v23(514LL, 0LL, 0LL, buffer_0, 512LL) < 0
|| strcmp(buffer_0, v33)
|| (int)(*(&treaty_registry + v24))(
260LL,
*(_QWORD *)(a2 + 32),
*(unsigned int *)(a2 + 40),
0LL,
0LL) < 0 )
{
++v24;
v23 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&treaty_registry + v24);
if ( !v23 )
goto LABEL_64;
}
v25 = (__int64)*(&treaty_registry + (int)v24);
if ( v25 )
{
*(_QWORD *)(a2 + 8) = v25;
sprintf(buffer_0, "%sed %s", v34, v33);
result = buffer_0;
}
else
{
result = 0LL;
}
}
else
{
LABEL_64:
result = 0LL;
}
}
}
}
}
}
else
{
LABEL_7:
v9 = container_registry;
if ( container_registry )
{
v10 = 1LL;
v11 = -1;
while ( 1 )
{
v12 = v10 - 1;
v18 = v9(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL);
if ( v18 == 1 )
break;
if ( !v18 && v11 < 0 )
v11 = v10 - 1;
v17 = v10++;
v9 = *(&container_registry + v10 - 1);
if ( !v9 )
{
if ( *(&container_registry + v17) || v11 < 0 )
goto LABEL_27;
goto LABEL_25;
}
}
if ( !*(&container_registry + v12) && v11 >= 0 )
{
LABEL_25:
*(_BYTE *)(a2 + 56) = 0;
v12 = v11;
}
v13 = (void (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&container_registry + v12);
if ( v13 )
goto LABEL_15;
}
LABEL_27:
*(_BYTE *)(a2 + 44) = 0;
if ( !v2 )
goto LABEL_51;
v19 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))treaty_registry;
if ( !treaty_registry )
goto LABEL_51;
v20 = 1LL;
do
{
v26 = v20 - 1;
if ( (int)v19(515LL, 0LL, 0LL, buffer_0, 512LL) >= 0
&& strstr(buffer_0, v2)
&& (int)(*(&treaty_registry + v20 - 1))(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL) >= 0 )
{
break;
}
v26 = v20++;
v19 = (__int64 (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&treaty_registry + v20 - 1);
}
while ( v19 );
if ( !*(&treaty_registry + v26) )
{
LABEL_51:
v29 = treaty_registry;
if ( !treaty_registry )
return 0LL;
v30 = 0LL;
v31 = -1;
while ( 1 )
{
v26 = v30;
v32 = v29(260LL, *(_QWORD *)(a2 + 16), *(unsigned int *)(a2 + 24), 0LL, 0LL);
if ( v32 == 1 )
break;
if ( !v32 && v31 < 0 )
v31 = v30;
++v30;
v29 = *(&treaty_registry + v30);
if ( !v29 )
goto LABEL_60;
}
if ( *(&treaty_registry + (int)v30) )
goto LABEL_48;
LABEL_60:
if ( v31 <= 0 )
return 0LL;
*(_BYTE *)(a2 + 56) = 0;
v26 = v31;
}
LABEL_48:
v27 = (int (__fastcall *)(__int64, _QWORD, _QWORD, char *, __int64))*(&treaty_registry + v26);
*(_QWORD *)a2 = v27;
v28 = v27(514LL, 0LL, 0LL, buffer_0, 512LL) < 0;
result = buffer_0;
if ( v28 )
result = 0LL;
}
return result;
}

original_code:
static char *deeper_babel_init(char *story_name, void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 int i;
 char *ext;
 static char buffer[512];
 int best_candidate;
 char buffert[512];
 if (story_name)
  {
   ext=strrchr(story_name,'.');
   if (ext) for(i=0;ext[i];i++) ext[i]=tolower(ext[i]);
  }
 else ext=((void *)0);
 best_candidate=-1;
 if (ext)
  for(i=0;container_registry[i];i++)
   if (container_registry[i](0x203,((void *)0),0,buffer,512) >=0 &&
       strstr(buffer,ext) &&
       container_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0)>=0)
    break;
  if (!ext || !container_registry[i])
  {
  for(i=0;container_registry[i];i++)
   {int l=container_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0);
    if (l==1)
    break;
    else if (l==0 && best_candidate < 0) best_candidate=i;
    }
}
 if (!container_registry[i] && best_candidate >=0) { bh->auth=0; i=best_candidate; }
 if (container_registry[i])
 {
   char buffer2[512];
   bh->treaty_handler=container_registry[i];
   container_registry[i](0x202,((void *)0),0,buffert,512);
   bh->blorb_mode=1;
   bh->story_file_blorbed_extent=container_registry[i](0x511,bh->story_file,bh->story_file_extent,((void *)0),0);
   if (bh->story_file_blorbed_extent>0) bh->story_file_blorbed=my_malloc(bh->story_file_blorbed_extent, "contained story file");
   if (bh->story_file_blorbed_extent<=0 ||
       container_registry[i](0x710,bh->story_file,bh->story_file_extent,buffer2,512)<0 ||
       container_registry[i](0x711,bh->story_file,bh->story_file_extent,bh->story_file_blorbed,bh->story_file_blorbed_extent)<=0
      )
    return ((void *)0);
   for(i=0;treaty_registry[i];i++)
    if (treaty_registry[i](0x202,((void *)0),0,buffer,512)>=0 &&
        strcmp(buffer,buffer2)==0 &&
        treaty_registry[i](0x104,bh->story_file_blorbed,bh->story_file_blorbed_extent,((void *)0),0)>=0)
     break;
  if (!treaty_registry[i])
   return ((void *)0);
  bh->treaty_backup=treaty_registry[i];
  sprintf(buffer,"%sed %s",buffert,buffer2);
  return buffer;
  }
 bh->blorb_mode=0;
 best_candidate=-1;
 if (ext)
  for(i=0;treaty_registry[i];i++)
   if (treaty_registry[i](0x203,((void *)0),0,buffer,512) >=0 &&
       strstr(buffer,ext) &&
       treaty_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0)>=0)
    break;
  if (!ext || !treaty_registry[i])
  {
  for(i=0;treaty_registry[i];i++)
   {int l;
   l=treaty_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0);
    if (l==1)
    break;
    else if (l==0 && best_candidate < 0) best_candidate=i;
    }
  }
  if (!treaty_registry[i])
   if (best_candidate>0) { i=best_candidate; bh->auth=0; }
   else return ((void *)0);
  bh->treaty_handler=treaty_registry[i];
  if (bh->treaty_handler(0x202,((void *)0),0,buffer,512)>=0)
  return buffer;
  return ((void *)0);
}

canonical_original_code:
static char *deeper_babel_init(char *story_name, void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 int i;
 char *ext;
 static char buffer[512];
 int best_candidate;
 char buffert[512];
 if (story_name)
  {
   ext=strrchr(story_name,'.');
   if (ext) for(i=0;ext[i];i++) ext[i]=tolower(ext[i]);
  }
 else ext=((void *)0);
 best_candidate=-1;
 if (ext)
  for(i=0;container_registry[i];i++)
   if (container_registry[i](0x203,((void *)0),0,buffer,512) >=0 &&
       strstr(buffer,ext) &&
       container_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0)>=0)
    break;
  if (!ext || !container_registry[i])
  {
  for(i=0;container_registry[i];i++)
   {int l = container_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0);
    if (l==1)
    break;
    else if (l==0 && best_candidate < 0) best_candidate=i;
    }
}
 if (!container_registry[i] && best_candidate >=0) { bh->auth=0; i=best_candidate; }
 if (container_registry[i])
 {
   char buffer2[512];
   bh->treaty_handler=container_registry[i];
   container_registry[i](0x202,((void *)0),0,buffert,512);
   bh->blorb_mode=1;
   bh->story_file_blorbed_extent=container_registry[i](0x511,bh->story_file,bh->story_file_extent,((void *)0),0);
   if (bh->story_file_blorbed_extent>0) bh->story_file_blorbed=my_malloc(bh->story_file_blorbed_extent, "contained story file");
   if (bh->story_file_blorbed_extent<=0 ||
       container_registry[i](0x710,bh->story_file,bh->story_file_extent,buffer2,512)<0 ||
       container_registry[i](0x711,bh->story_file,bh->story_file_extent,bh->story_file_blorbed,bh->story_file_blorbed_extent)<=0
      )
    return ((void *)0);
   for(i=0;treaty_registry[i];i++)
    if (treaty_registry[i](0x202,((void *)0),0,buffer,512)>=0 &&
        strcmp(buffer,buffer2)==0 &&
        treaty_registry[i](0x104,bh->story_file_blorbed,bh->story_file_blorbed_extent,((void *)0),0)>=0)
     break;
  if (!treaty_registry[i])
   return ((void *)0);
  bh->treaty_backup=treaty_registry[i];
  sprintf(buffer,"%sed %s",buffert,buffer2);
  return buffer;
  }
 bh->blorb_mode=0;
 best_candidate=-1;
 if (ext)
  for(i=0;treaty_registry[i];i++)
   if (treaty_registry[i](0x203,((void *)0),0,buffer,512) >=0 &&
       strstr(buffer,ext) &&
       treaty_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0)>=0)
    break;
  if (!ext || !treaty_registry[i])
  {
  for(i=0;treaty_registry[i];i++)
   {int l;
   l=treaty_registry[i](0x104,bh->story_file,bh->story_file_extent,((void *)0),0);
    if (l==1)
    break;
    else if (l==0 && best_candidate < 0) best_candidate=i;
    }
  }
  if (!treaty_registry[i])
   if (best_candidate>0) { i=best_candidate; bh->auth=0; }
   else return ((void *)0);
  bh->treaty_handler=treaty_registry[i];
  if (bh->treaty_handler(0x202,((void *)0),0,buffer,512)>=0)
  return buffer;
  return ((void *)0);
}

variable_types:
bhp
void *

variable_types: struct babel_handler { int (*treaty_handler)(int selector, void *, int, void *, int); int (*treaty_backup)(int selector, void *, int, void *, int); void *story_file; int story_file_extent; void *story_file_blorbed; int story_file_blorbed_extent; char blorb_mode; char *format_name; char auth; } *

variable_types:
ext
char *

variable_types:
buffer
char [512]

variable_types:
buffert
char [512]

variable_types: l int


repo: ricpelo/elcirculo

decompiled_code:
char *__fastcall babel_init_ctx(char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // rbx

v2 = deep_babel_init(a1, a2);
v3 = v2;
if ( v2 )
*(_QWORD *)(a2 + 48) = strdup(v2);
return v3;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // rbx

v2 = func1(a1, a2);
v3 = v2;
if ( v2 )
*(_QWORD *)(a2 + 48) = strdup(v2);
return v3;
}

original_code:
char *babel_init_ctx(char *sf, void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 char *b;
 b=deep_babel_init(sf,bh);
 if (b) bh->format_name=strdup(b);
 return b;
}

canonical_original_code:
char *babel_init_ctx(char *sf, void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 char *b;
 b=deep_babel_init(sf,bh);
 if (b) bh->format_name=strdup(b);
 return b;
}

variable_types:
sf
char *

variable_types:
b
char *

return_type: char *

user_defined_types: struct babel_handler { int (*treaty_handler)(int selector, void *, int, void *, int); int (*treaty_backup)(int selector, void *, int, void *, int); void *story_file; int story_file_extent; void *story_file_blorbed; int story_file_blorbed_extent; char blorb_mode; char *format_name; char auth; }


decompiled_code:
char *__fastcall babel_init(char *a1)
{
return babel_init_ctx(a1, (__int64)&default_ctx);
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
return func2(a1, (__int64)&default_ctx);
}

original_code:
char *babel_init(char *sf)
{
  return babel_init_ctx(sf, &default_ctx);
}


decompiled_code:
char *__fastcall babel_init_raw_ctx(void *src, unsigned int a2, __int64 a3)
{
void *v4; // rax
char *v5; // rax
char *v6; // rbp

*(_QWORD *)a3 = 0LL;
*(_QWORD *)(a3 + 8) = 0LL;
*(_QWORD *)(a3 + 16) = 0LL;
*(_QWORD *)(a3 + 32) = 0LL;
*(_DWORD *)(a3 + 40) = 0;
*(_QWORD *)(a3 + 48) = 0LL;
*(_DWORD *)(a3 + 24) = a2;
*(_BYTE *)(a3 + 56) = 1;
v4 = (void *)my_malloc(a2, "story file storage");
*(_QWORD *)(a3 + 16) = v4;
memcpy(v4, src, (int)a2);
v5 = deeper_babel_init(0LL, a3);
v6 = v5;
if ( v5 )
*(_QWORD *)(a3 + 48) = strdup(v5);
return v6;
}

original_code:
char *babel_init_raw_ctx(void *sf, int32 extent, void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 char *b;
 bh->treaty_handler=((void *)0);
 bh->treaty_backup=((void *)0);
 bh->story_file=((void *)0);
 bh->story_file_extent=0;
 bh->story_file_blorbed=((void *)0);
 bh->story_file_blorbed_extent=0;
 bh->format_name=((void *)0);
 bh->story_file_extent=extent;
 bh->auth=1;
 bh->story_file=my_malloc(bh->story_file_extent,"story file storage");
 memcpy(bh->story_file,sf,extent);
 b=deeper_babel_init(((void *)0), bhp);
 if (b) bh->format_name=strdup(b);
 return b;
}

canonical_original_code:
char *babel_init_raw_ctx(void *sf, int extent, void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 char *b;
 bh->treaty_handler=((void *)0);
 bh->treaty_backup=((void *)0);
 bh->story_file=((void *)0);
 bh->story_file_extent=0;
 bh->story_file_blorbed=((void *)0);
 bh->story_file_blorbed_extent=0;
 bh->format_name=((void *)0);
 bh->story_file_extent=extent;
 bh->auth=1;
 bh->story_file=my_malloc(bh->story_file_extent,"story file storage");
 memcpy(bh->story_file,sf,extent);
 b=deeper_babel_init(((void *)0), bhp);
 if (b) bh->format_name=strdup(b);
 return b;
}

variable_types:
sf
void *

variable_types: extent int


decompiled_code:
char *__fastcall babel_init_raw(void *a1, unsigned int a2)
{
return babel_init_raw_ctx(a1, a2, (__int64)&default_ctx);
}

canonical_decompiled_code:
char *__fastcall func5(void *a1, unsigned int a2)
{
return func4(a1, a2, (__int64)&default_ctx);
}

original_code:
char *babel_init_raw(void *sf, int32 extent)
{
  return babel_init_raw_ctx(sf, extent, &default_ctx);
}

canonical_original_code:
char *babel_init_raw(void *sf, int extent)
{
  return babel_init_raw_ctx(sf, extent, &default_ctx);
}


decompiled_code:
void __fastcall babel_release_ctx(_QWORD *a1)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = (void *)a1[2];
if ( v2 )
free(v2);
a1[2] = 0LL;
v3 = (void *)a1[4];
if ( v3 )
free(v3);
a1[4] = 0LL;
v4 = (void *)a1[6];
if ( v4 )
free(v4);
a1[6] = 0LL;
}

canonical_decompiled_code:
void __fastcall func6(_QWORD *a1)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = (void *)a1[2];
if ( v2 )
free(v2);
a1[2] = 0LL;
v3 = (void *)a1[4];
if ( v3 )
free(v3);
a1[4] = 0LL;
v4 = (void *)a1[6];
if ( v4 )
free(v4);
a1[6] = 0LL;
}

original_code:
void babel_release_ctx(void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 if (bh->story_file) free(bh->story_file);
 bh->story_file=((void *)0);
 if (bh->story_file_blorbed) free(bh->story_file_blorbed);
 bh->story_file_blorbed=((void *)0);
 if (bh->format_name) free(bh->format_name);
 bh->format_name=((void *)0);
}

canonical_original_code:
void babel_release_ctx(void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 if (bh->story_file) free(bh->story_file);
 bh->story_file=((void *)0);
 if (bh->story_file_blorbed) free(bh->story_file_blorbed);
 bh->story_file_blorbed=((void *)0);
 if (bh->format_name) free(bh->format_name);
 bh->format_name=((void *)0);
}

return_type: void


decompiled_code:
void babel_release()
{
babel_release_ctx(default_ctx);
}

canonical_decompiled_code:
void func7()
{
func6(default_ctx);
}

original_code:
void babel_release()
{
 babel_release_ctx(&default_ctx);
}


decompiled_code:
__int64 __fastcall babel_md5_ifid_ctx(char *s, int a2, __int64 a3)
{
__int64 result; // rax
char *v5; // rbx
char *v6; // rbp
_BYTE v7[16]; // [rsp-10h] [rbp-98h] BYREF
char v8[136]; // [rsp+0h] [rbp-88h] BYREF

result = 0LL;
if ( a2 > 32 && *(_QWORD *)(a3 + 16) )
{
md5_init(v8);
md5_append(v8, *(_QWORD *)(a3 + 16), *(unsigned int *)(a3 + 24));
md5_finish(v8, v7);
v5 = v7;
v6 = s;
do
{
sprintf(v6, "%02X", (unsigned __int8)*v5++);
v6 += 2;
}
while ( v5 != v8 );
s[32] = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s, int a2, __int64 a3)
{
__int64 result; // rax
char *v5; // rbx
char *v6; // rbp
_BYTE v7[16]; // [rsp-10h] [rbp-98h] BYREF
char v8[136]; // [rsp+0h] [rbp-88h] BYREF

result = 0LL;
if ( a2 > 32 && *(_QWORD *)(a3 + 16) )
{
md5_init(v8);
md5_append(v8, *(_QWORD *)(a3 + 16), *(unsigned int *)(a3 + 24));
md5_finish(v8, v7);
v5 = v7;
v6 = s;
do
{
sprintf(v6, "%02X", (unsigned __int8)*v5++);
v6 += 2;
}
while ( v5 != v8 );
s[32] = 0;
result = 1LL;
}
return result;
}

original_code:
int32 babel_md5_ifid_ctx(char *buffer, int32 extent, void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 md5_state_t md5;
 int i;
 unsigned char ob[16];
 if (extent <33 || bh->story_file==((void *)0))
  return 0;
 md5_init(&md5);
 md5_append(&md5,bh->story_file,bh->story_file_extent);
 md5_finish(&md5,ob);
 for(i=0;i<16;i++)
  sprintf(buffer+(2*i),"%02X",ob[i]);
 buffer[32]=0;
 return 1;
}

canonical_original_code:
int babel_md5_ifid_ctx(char *buffer, int extent, void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 struct md5_state_s md5;
 int i;
 unsigned char ob[16];
 if (extent <33 || bh->story_file==((void *)0))
  return 0;
 md5_init(&md5);
 md5_append(&md5,bh->story_file,bh->story_file_extent);
 md5_finish(&md5,ob);
 for(i=0;i<16;i++)
  sprintf(buffer+(2*i),"%02X",ob[i]);
 buffer[32]=0;
 return 1;
}

variable_types:
buffer
char *

variable_types: struct md5_state_s { unsigned int count[2]; unsigned int abcd[4]; unsigned char buf[64]; }

variable_types: i int

variable_types:
ob
unsigned char [16]

return_type: int


decompiled_code:
__int64 __fastcall babel_md5_ifid(char *a1, int a2)
{
return babel_md5_ifid_ctx(a1, a2, (__int64)default_ctx);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, int a2)
{
return func8(a1, a2, (__int64)default_ctx);
}

original_code:
int32 babel_md5_ifid(char *buffer, int32 extent)
{
 return babel_md5_ifid_ctx(buffer, extent,
                &default_ctx);
}

canonical_original_code:
int babel_md5_ifid(char *buffer, int extent)
{
 return babel_md5_ifid_ctx(buffer, extent,
                &default_ctx);
}


decompiled_code:
__int64 __fastcall babel_treaty_ctx(__int64 a1, char *a2, unsigned int a3, __int64 a4)
{
__int64 result; // rax
bool v7; // dl
size_t v8; // rax

if ( (a1 & 0x100) != 0 || !*(_BYTE *)(a4 + 44) )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, char *, _QWORD))a4)(
(unsigned int)a1,
*(_QWORD *)(a4 + 16),
*(unsigned int *)(a4 + 24),
a2,
a3);
if ( (((_DWORD)result + 2) & 0xFFFFFFFD) != 0 )
{
v7 = (_DWORD)a1 == 776;
goto LABEL_11;
}
if ( *(_BYTE *)(a4 + 44) )
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, char *, _QWORD))(a4 + 8))(
(unsigned int)a1,
*(_QWORD *)(a4 + 32),
*(unsigned int *)(a4 + 40),
a2,
a3);
}
else
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD, char *, _QWORD))(a4 + 8))(
a1,
*(_QWORD *)(a4 + 32),
*(unsigned int *)(a4 + 40),
a2,
a3);
}
v7 = (_DWORD)a1 == 776;
if ( !(_DWORD)result && (_DWORD)a1 == 776 )
return babel_md5_ifid_ctx(a2, a3, a4);
LABEL_11:
if ( (_DWORD)result == -4 && v7 )
{
v8 = strlen(a2);
result = babel_md5_ifid_ctx(&a2[v8], a3 - (unsigned int)v8, a4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char *a2, unsigned int a3, __int64 a4)
{
__int64 result; // rax
bool v7; // dl
size_t v8; // rax

if ( (a1 & 0x100) != 0 || !*(_BYTE *)(a4 + 44) )
{
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, char *, _QWORD))a4)(
(unsigned int)a1,
*(_QWORD *)(a4 + 16),
*(unsigned int *)(a4 + 24),
a2,
a3);
if ( (((_DWORD)result + 2) & 0xFFFFFFFD) != 0 )
{
v7 = (_DWORD)a1 == 776;
goto LABEL_11;
}
if ( *(_BYTE *)(a4 + 44) )
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, char *, _QWORD))(a4 + 8))(
(unsigned int)a1,
*(_QWORD *)(a4 + 32),
*(unsigned int *)(a4 + 40),
a2,
a3);
}
else
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD, char *, _QWORD))(a4 + 8))(
a1,
*(_QWORD *)(a4 + 32),
*(unsigned int *)(a4 + 40),
a2,
a3);
}
v7 = (_DWORD)a1 == 776;
if ( !(_DWORD)result && (_DWORD)a1 == 776 )
return func8(a2, a3, a4);
LABEL_11:
if ( (_DWORD)result == -4 && v7 )
{
v8 = strlen(a2);
result = func8(&a2[v8], a3 - (unsigned int)v8, a4);
}
return result;
}

original_code:
int32 babel_treaty_ctx(int32 sel, void *output, int32 output_extent,void *bhp)
{
 int32 rv;
 struct babel_handler *bh=(struct babel_handler *) bhp;
 if (!(sel & 0x100) && bh->blorb_mode)
  rv=bh->treaty_backup(sel,bh->story_file_blorbed,bh->story_file_blorbed_extent,output, output_extent);
 else
 {
  rv=bh->treaty_handler(sel,bh->story_file,bh->story_file_extent,output,output_extent);
  if ((!rv|| rv==-2) && bh->blorb_mode)
   rv=bh->treaty_backup(sel,bh->story_file_blorbed,bh->story_file_blorbed_extent,output, output_extent);
  }
 if (!rv && sel==0x308)
  return babel_md5_ifid_ctx(output,output_extent, bh);
 if (rv==-4 && sel==0x308)
  return babel_md5_ifid_ctx((void *)((char *) output+strlen((char *)output)),
                            output_extent-strlen((char *)output),
                            bh);
 return rv;
}

canonical_original_code:
int babel_treaty_ctx(int sel, void *output, int output_extent, void *bhp)
{
 int rv;
 struct babel_handler *bh = (struct babel_handler *) bhp;
 if (!(sel & 0x100) && bh->blorb_mode)
  rv=bh->treaty_backup(sel,bh->story_file_blorbed,bh->story_file_blorbed_extent,output, output_extent);
 else
 {
  rv=bh->treaty_handler(sel,bh->story_file,bh->story_file_extent,output,output_extent);
  if ((!rv|| rv==-2) && bh->blorb_mode)
   rv=bh->treaty_backup(sel,bh->story_file_blorbed,bh->story_file_blorbed_extent,output, output_extent);
  }
 if (!rv && sel==0x308)
  return babel_md5_ifid_ctx(output,output_extent, bh);
 if (rv==-4 && sel==0x308)
  return babel_md5_ifid_ctx((void *)((char *) output+strlen((char *)output)),
                            output_extent-strlen((char *)output),
                            bh);
 return rv;
}

variable_types: sel int

variable_types:
output
void *

variable_types: rv int


decompiled_code:
__int64 __fastcall babel_treaty(__int64 a1, char *a2, unsigned int a3)
{
return babel_treaty_ctx(a1, a2, a3, (__int64)default_ctx);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char *a2, unsigned int a3)
{
return func10(a1, a2, a3, (__int64)default_ctx);
}

original_code:
int32 babel_treaty(int32 sel, void *output, int32 output_extent)
{
 return babel_treaty_ctx(sel, output, output_extent, &default_ctx);
}

canonical_original_code:
int babel_treaty(int sel, void *output, int output_extent)
{
 return babel_treaty_ctx(sel, output, output_extent, &default_ctx);
}


decompiled_code:
__int64 __fastcall babel_get_format_ctx(__int64 a1)
{
return *(_QWORD *)(a1 + 48);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(_QWORD *)(a1 + 48);
}

original_code:
char *babel_get_format_ctx(void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 return bh->format_name;
}

canonical_original_code:
char *babel_get_format_ctx(void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 return bh->format_name;
}

variable_types:
bhp
void *


decompiled_code:
__int64 babel_get_format()
{
return babel_get_format_ctx((__int64)default_ctx);
}

canonical_decompiled_code:
__int64 func13()
{
return func12((__int64)default_ctx);
}

original_code:
char *babel_get_format()
{
 return babel_get_format_ctx(&default_ctx);
}


decompiled_code:
__int64 get_babel_ctx()
{
return my_malloc(64LL, "babel handler context");
}

canonical_decompiled_code:
__int64 func14()
{
return my_malloc(64LL, "babel handler context");
}

original_code:
void *get_babel_ctx()
{
 return my_malloc(sizeof(struct babel_handler), "babel handler context");
}

return_type: void *


decompiled_code:
void __fastcall release_babel_ctx(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func15(void *a1)
{
free(a1);
}

original_code:
void release_babel_ctx(void *b)
{
 free(b);
}

variable_types:
b
void *


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

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

original_code:
int32 babel_get_length_ctx(void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 return bh->story_file_extent;
}

canonical_original_code:
int babel_get_length_ctx(void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 return bh->story_file_extent;
}

variable_types: struct babel_handler { int (*treaty_handler)(int selector, void *, int, void *, int); int (*treaty_backup)(int selector, void *, int, void *, int); void *story_file; int story_file_extent; void *story_file_blorbed; int story_file_blorbed_extent; char blorb_mode; char *format_name; char auth; } *


decompiled_code:
__int64 babel_get_length()
{
return babel_get_length_ctx((__int64)default_ctx);
}

canonical_decompiled_code:
__int64 func17()
{
return func16((__int64)default_ctx);
}

original_code:
int32 babel_get_length()
{
 return babel_get_length_ctx(&default_ctx);
}

canonical_original_code:
int babel_get_length()
{
 return babel_get_length_ctx(&default_ctx);
}


decompiled_code:
__int64 __fastcall babel_get_authoritative_ctx(__int64 a1)
{
return (unsigned int)*(char *)(a1 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return (unsigned int)*(char *)(a1 + 56);
}

original_code:
int32 babel_get_authoritative_ctx(void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 return bh->auth;
}

canonical_original_code:
int babel_get_authoritative_ctx(void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 return bh->auth;
}


decompiled_code:
__int64 babel_get_authoritative()
{
return babel_get_authoritative_ctx((__int64)default_ctx);
}

canonical_decompiled_code:
__int64 func19()
{
return func18((__int64)default_ctx);
}

original_code:
int32 babel_get_authoritative()
{
  return babel_get_authoritative_ctx(&default_ctx);
}

canonical_original_code:
int babel_get_authoritative()
{
  return babel_get_authoritative_ctx(&default_ctx);
}


decompiled_code:
__int64 __fastcall babel_get_file_ctx(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
void *babel_get_file_ctx(void *bhp)
{
 struct babel_handler *bh=(struct babel_handler *) bhp;
 return bh->story_file;
}

canonical_original_code:
void *babel_get_file_ctx(void *bhp)
{
 struct babel_handler *bh = (struct babel_handler *) bhp;
 return bh->story_file;
}


decompiled_code:
__int64 babel_get_file()
{
return babel_get_file_ctx((__int64)default_ctx);
}

canonical_decompiled_code:
__int64 func21()
{
return func20((__int64)default_ctx);
}

original_code:
void *babel_get_file()
{
 return babel_get_file_ctx(&default_ctx);
}


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

if ( *(_BYTE *)(a1 + 44) )
result = *(unsigned int *)(a1 + 40);
else
result = *(unsigned int *)(a1 + 24);
return result;
}

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

if ( *(_BYTE *)(a1 + 44) )
result = *(unsigned int *)(a1 + 40);
else
result = *(unsigned int *)(a1 + 24);
return result;
}

original_code:
int32 babel_get_story_length_ctx(void *ctx)
{
  struct babel_handler *bh=(struct babel_handler *) ctx;
  if (bh->blorb_mode) return bh->story_file_blorbed_extent;
  return bh->story_file_extent;
}

canonical_original_code:
int babel_get_story_length_ctx(void *ctx)
{
  struct babel_handler *bh = (struct babel_handler *) ctx;
  if (bh->blorb_mode) return bh->story_file_blorbed_extent;
  return bh->story_file_extent;
}

variable_types:
ctx
void *


decompiled_code:
__int64 babel_get_story_length()
{
return babel_get_story_length_ctx((__int64)default_ctx);
}

canonical_decompiled_code:
__int64 func23()
{
return func22((__int64)default_ctx);
}

original_code:
int32 babel_get_story_length()
{
 return babel_get_story_length_ctx(&default_ctx);
}

canonical_original_code:
int babel_get_story_length()
{
 return babel_get_story_length_ctx(&default_ctx);
}


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

if ( *(_BYTE *)(a1 + 44) )
result = *(_QWORD *)(a1 + 32);
else
result = *(_QWORD *)(a1 + 16);
return result;
}

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

if ( *(_BYTE *)(a1 + 44) )
result = *(_QWORD *)(a1 + 32);
else
result = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
void *babel_get_story_file_ctx(void *ctx)
{
  struct babel_handler *bh=(struct babel_handler *) ctx;
  if (bh->blorb_mode) return bh->story_file_blorbed;
  return bh->story_file;
}

canonical_original_code:
void *babel_get_story_file_ctx(void *ctx)
{
  struct babel_handler *bh = (struct babel_handler *) ctx;
  if (bh->blorb_mode) return bh->story_file_blorbed;
  return bh->story_file;
}


decompiled_code:
__int64 babel_get_story_file()
{
return babel_get_story_file_ctx((__int64)default_ctx);
}

canonical_decompiled_code:
__int64 func25()
{
return func24((__int64)default_ctx);
}

original_code:
void *babel_get_story_file()
{
 return babel_get_story_file_ctx(&default_ctx);
}


decompiled_code:
__int64 __fastcall read_alan_int(unsigned int *a1)
{
return _byteswap_ulong(*a1);
}

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

original_code:
static int32 read_alan_int(unsigned char *from)
{
 return ((unsigned long int) from[3])| ((unsigned long int)from[2] << 8) |
       ((unsigned long int) from[1]<<16)| ((unsigned long int)from[0] << 24);
}

canonical_original_code:
static int read_alan_int(unsigned char *from)
{
 return ((unsigned long) from[3])| ((unsigned long)from[2] << 8) |
       ((unsigned long) from[1]<<16)| ((unsigned long)from[0] << 24);
}

variable_types:
from
unsigned char *


original_code:
int32 alan_treaty(int32 selector,
                   void *story_file, int32 extent,
                   void *output, int32 output_extent)
{
 int32 ll, csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((signed) strlen("http://www.alanif.se/")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.alanif.se/");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"alan",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".acd")+1) < 512 ? (strlen(".acd")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".acd", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

canonical_original_code:
int alan_treaty(int selector, void *story_file, int extent, void *output, int output_extent)
{
 int ll; int csf;
 if ((0x100 & selector) &&
     (csf=claim_story_file(story_file, extent))<0)
         return -1;
 if ((0x200 & selector) &&
     (output_extent ==0 ||
     output==((void *)0)))
        return -3;
 switch(selector)
 {
  case 0x201:
                do { if (output_extent < ((int) strlen("http://www.alanif.se/")+1)) return -3; } while (0);
                strcpy((char *) output,"http://www.alanif.se/");
                return 0;
  case 0x202:
                do { if (output_extent < (512)) return -3; } while (0);
                strncpy((char *) output,"alan",output_extent-1);
                return 0;
  case 0x203:
                ll=(strlen(".acd")+1) < 512 ? (strlen(".acd")+1):512;
                do { if (output_extent < (ll)) return -3; } while (0);
                strncpy((char *) output, ".acd", output_extent);
                return 0;
  case 0x104:
                return csf;
  case 0x105:
  case 0x309:
                return 0;
  case 0x106:
  case 0x107:
  case 0x30A:
                return 0;
  case 0x308:
                return get_story_file_IFID(story_file, extent, (char *)output, output_extent);
  case 0x30B:
                return get_story_file_extension(story_file, extent, (char *)output, output_extent);
 }
 return -2;
}

variable_types: selector int

variable_types: ll int

variable_types: csf int


decompiled_code:
__int64 __fastcall claim_story_file(unsigned int *a1, int a2)
{
int v2; // er13
unsigned int v3; // edx
unsigned int *v4; // rbx
int v5; // er13
unsigned __int8 *v6; // rax
int v7; // ebx
int v8; // eax
int v9; // edx
int v10; // eax

if ( a2 <= 159 )
return 0xFFFFFFFFLL;
if ( !memcmp(a1, "ALAN", 4uLL) )
{
v8 = read_alan_int(a1 + 3);
v3 = -1;
if ( a2 >> 2 >= v8 )
{
v9 = 4 * v8;
if ( 4 * v8 <= 184 )
{
v3 = -1;
}
else
{
v10 = 184;
do
++v10;
while ( v9 != v10 );
v3 = -1;
}
}
}
else
{
v2 = read_alan_int(a1 + 1);
v3 = -1;
if ( a2 >> 2 >= v2 )
{
v4 = a1 + 6;
do
{
if ( a2 >> 2 < (int)read_alan_int(v4) )
return (unsigned int)-1;
++v4;
}
while ( v4 != a1 + 21 );
v5 = 4 * v2;
if ( v5 <= 160 )
{
v7 = 0;
}
else
{
v6 = (unsigned __int8 *)(a1 + 40);
v7 = 0;
do
v7 += *v6++;
while ( (unsigned __int8 *)((char *)a1 + (unsigned int)(v5 - 161) + 161) != v6 );
}
v3 = 2 * ((unsigned int)read_alan_int(a1 + 38) == v7) - 1;
}
}
return v3;
}

original_code:
static int32 claim_story_file(void *story_file, int32 extent)
{
 unsigned char *sf = (unsigned char *) story_file;
 int32 bf, i, crc=0;
 if (extent < 160) return -1;
 if (memcmp(sf,"ALAN",4))
 {
 bf=read_alan_int(sf+4);
 if (bf > extent/4) return -1;
 for (i=24;i<81;i+=4)
 if (read_alan_int(sf+i) > extent/4) return -1;
 for (i=160;i<(bf*4);i++)
 crc+=sf[i];
 if (crc!=read_alan_int(sf+152)) return -1;
 return 1;
 }
 else
 {
   bf=read_alan_int(sf+12);
   if (bf > (extent/4)) return -1;
   for (i=184;i<(bf*4);i++)
    crc+=sf[i];
 if (crc!=read_alan_int(sf+176)) return -1;
 }
 return -1;
}

canonical_original_code:
static int claim_story_file(void *story_file, int extent)
{
 unsigned char *sf = (unsigned char *) story_file;
 int bf; int i; int crc = 0;
 if (extent < 160) return -1;
 if (memcmp(sf,"ALAN",4))
 {
 bf=read_alan_int(sf+4);
 if (bf > extent/4) return -1;
 for (i=24;i<81;i+=4)
 if (read_alan_int(sf+i) > extent/4) return -1;
 for (i=160;i<(bf*4);i++)
 crc+=sf[i];
 if (crc!=read_alan_int(sf+152)) return -1;
 return 1;
 }
 else
 {
   bf=read_alan_int(sf+12);
   if (bf > (extent/4)) return -1;
   for (i=184;i<(bf*4);i++)
    crc+=sf[i];
 if (crc!=read_alan_int(sf+176)) return -1;
 }
 return -1;
}

variable_types:
sf
unsigned char *

variable_types: bf int

variable_types: crc int


decompiled_code:
size_t __fastcall get_story_file_extension(__int64 a1, int a2, void *a3, int a4)
{
__int64 v6; // rax
int v7; // ecx
char v8; // dl
__int64 v9; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v6 = 1LL;
do
{
v7 = v6;
v8 = byte_362[v6++];
}
while ( v8 && v8 != 44 );
if ( a4 <= v7 )
return 4294967293LL;
v9 = v7;
memcpy(a3, byte_362, v7);
*((_BYTE *)a3 + v9) = 0;
return strlen((const char *)a3);
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1, int a2, void *a3, int a4)
{
__int64 v6; // rax
int v7; // ecx
char v8; // dl
__int64 v9; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v6 = 1LL;
do
{
v7 = v6;
v8 = byte_362[v6++];
}
while ( v8 && v8 != 44 );
if ( a4 <= v7 )
return 4294967293LL;
v9 = v7;
memcpy(a3, byte_362, v7);
*((_BYTE *)a3 + v9) = 0;
return strlen((const char *)a3);
}

original_code:
static int32 get_story_file_extension(void *sf, int32 extent, char *out, int32 output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".acd"[i] && ".acd"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".acd",i);
 out[i]=0;
 return strlen(out);
}

canonical_original_code:
static int get_story_file_extension(void *sf, int extent, char *out, int output_extent)
{
 int i;
 if (!sf || !extent) return -1;
 for(i=0;".acd"[i] && ".acd"[i]!=',';i++);
 do { if (output_extent < (i+1)) return -3; } while (0);
 memcpy(out,".acd",i);
 out[i]=0;
 return strlen(out);
}

variable_types:
sf
void *

variable_types: extent int

variable_types:
out
char *


decompiled_code:
__int64 __fastcall DL_ISO8583_DEFS_1987_GetHandler(__int64 a1)
{
return DL_ISO8583_COMMON_SetHandler(&iso8583_1987_fields, 129LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return DL_ISO8583_COMMON_SetHandler(&iso8583_1987_fields, 129LL, a1);
}

original_code:
void DL_ISO8583_DEFS_1987_GetHandler ( DL_ISO8583_HANDLER *oHandler )
{
 DL_ISO8583_COMMON_SetHandler(
  _iso8583_1987_fields,
  (DL_UINT8)(sizeof(_iso8583_1987_fields)/sizeof(DL_ISO8583_FIELD_DEF)),
  oHandler);
 return;
}

canonical_original_code:
void DL_ISO8583_DEFS_1987_GetHandler(struct DL_ISO8583_HANDLER_S *oHandler)
{
 DL_ISO8583_COMMON_SetHandler(
  _iso8583_1987_fields,
  (DL_UINT8)(sizeof(_iso8583_1987_fields)/sizeof(DL_ISO8583_FIELD_DEF)),
  oHandler);
 return;
}

variable_types: struct DL_ISO8583_HANDLER_S { struct DL_ISO8583_FIELD_DEF_S { unsigned char fieldType; unsigned int len; unsigned char varLen; } *fieldArr; unsigned char fieldItems; } *

user_defined_types: struct DL_ISO8583_HANDLER_S { struct DL_ISO8583_FIELD_DEF_S *fieldArr; unsigned char fieldItems; }


repo: sabotage-linux/gettext-tiny

original_code:
static inline enum po_error poparser_clean(struct po_parser *p, po_message_t msg) {
 if (p->strcnt) {
  if (p->first) p->first = 0;
  msg->strlen[p->strcnt] = 0;
  switch (msg->sysdep) {
  case (1 << st_priu32):
  case (1 << st_priu64):
   msg->sysdep = 2;
   break;
  case (1 << st_priu32)|(1 << st_priu64):
   msg->sysdep = 3;
   break;
  default:
   msg->sysdep = 1;
   break;
  }
  if (p->cb)
   p->cb(msg, p->cbdata);
  msg->sysdep = 0;
  msg->ctxt_len = 0;
  msg->id_len = 0;
  msg->plural_len = 0;
  msg->flags = 0;
  p->strcnt = 0;
 }
 return po_success;
}

canonical_original_code:
static inline enum po_error poparser_clean(struct po_parser *p, struct po_message *msg) {
 if (p->strcnt) {
  if (p->first) p->first = 0;
  msg->strlen[p->strcnt] = 0;
  switch (msg->sysdep) {
  case (1 << st_priu32):
  case (1 << st_priu64):
   msg->sysdep = 2;
   break;
  case (1 << st_priu32)|(1 << st_priu64):
   msg->sysdep = 3;
   break;
  default:
   msg->sysdep = 1;
   break;
  }
  if (p->cb)
   p->cb(msg, p->cbdata);
  msg->sysdep = 0;
  msg->ctxt_len = 0;
  msg->id_len = 0;
  msg->plural_len = 0;
  msg->flags = 0;
  p->strcnt = 0;
 }
 return po_success;
}

variable_types: struct po_parser { struct po_header { char charset[12]; unsigned int nplurals; } hdr; struct po_message { char *ctxt; char *id; char *plural; char *str[6]; int sysdep; unsigned long ctxt_len; unsigned long id_len; unsigned long plural_len; unsigned long strlen[6]; int flags; } msg; enum po_stage { ps_size=0, ps_parse=1, ps_max=expr } stage; _Bool first; _Bool strict; void *cd; enum po_entry { po_ctxt=0, po_id=1, po_plural=2, po_str=3 } previous; unsigned int strcnt; unsigned long max_ctxt_len; unsigned long max_id_len; unsigned long max_plural_len; unsigned long max_strlen[6]; char *buf; unsigned long bufsize; int (*cb)(struct po_message *msg, void *user); void *cbdata; } *

variable_types:
msg
struct po_message *

return_type: enum po_error { po_success=0, po_unsupported_charset=1, po_failed_iconv=2, po_excepted_token=3, po_plurals_overflow=4, po_invalid_entry=5, po_internal=6, po_error_last=expr }

user_defined_types: struct po_parser { struct po_header hdr; struct po_message msg; enum po_stage stage; _Bool first; _Bool strict; void *cd; enum po_entry previous; unsigned int strcnt; unsigned long max_ctxt_len; unsigned long max_id_len; unsigned long max_plural_len; unsigned long max_strlen[6]; char *buf; unsigned long bufsize; int (*cb)(struct po_message *msg, void *user); void *cbdata; }


decompiled_code:
__int64 __fastcall poparser_feed_hdr(char *fromcode, char *haystack)
{
__int64 result; // rax
char *v3; // rax
char *v4; // r13
char v5; // bl
const unsigned __int16 *v6; // rdx
_BYTE *v7; // rax
_BYTE *v8; // rbx
unsigned __int64 v9; // rdx
iconv_t v10; // rax
char *v11; // rdx

if ( !fromcode[180] )
return 0LL;
result = 0LL;
if ( haystack )
{
v3 = strstr(haystack, "charset=");
v4 = v3;
if ( !v3 )
{
LABEL_13:
v11 = strstr(haystack, "nplurals=");
result = 0LL;
if ( v11 )
{
*((_DWORD *)fromcode + 3) = v11[9] - 48;
result = 0LL;
}
return result;
}
v5 = *v3;
if ( !*v3 || v5 == 92 )
return 0xFFFFFFFFLL;
v6 = *_ctype_b_loc();
v7 = v4;
do
{
if ( (v6[v5] & 0x2000) != 0 )
break;
v5 = *++v7;
if ( !*v7 )
break;
}
while ( v5 != 92 );
v8 = (_BYTE *)(v7 - v4);
v9 = v7 - v4 - 7;
result = 0xFFFFFFFFLL;
if ( v9 <= 0xC )
{
memcpy(fromcode, v4 + 8, (size_t)(v8 - 8));
v8[(_QWORD)fromcode - 8] = 0;
v10 = iconv_open("UTF-8", fromcode);
if ( v10 == (iconv_t)-1LL )
{
*((_QWORD *)fromcode + 23) = 0LL;
result = 0xFFFFFFFFLL;
if ( fromcode[181] )
return result;
}
else
{
*((_QWORD *)fromcode + 23) = v10;
}
goto LABEL_13;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *fromcode, char *haystack)
{
__int64 result; // rax
char *v3; // rax
char *v4; // r13
char v5; // bl
const unsigned __int16 *v6; // rdx
_BYTE *v7; // rax
_BYTE *v8; // rbx
unsigned __int64 v9; // rdx
iconv_t v10; // rax
char *v11; // rdx

if ( !fromcode[180] )
return 0LL;
result = 0LL;
if ( haystack )
{
v3 = strstr(haystack, "charset=");
v4 = v3;
if ( !v3 )
{
LABEL_13:
v11 = strstr(haystack, "nplurals=");
result = 0LL;
if ( v11 )
{
*((_DWORD *)fromcode + 3) = v11[9] - 48;
result = 0LL;
}
return result;
}
v5 = *v3;
if ( !*v3 || v5 == 92 )
return 0xFFFFFFFFLL;
v6 = *_ctype_b_loc();
v7 = v4;
do
{
if ( (v6[v5] & 0x2000) != 0 )
break;
v5 = *++v7;
if ( !*v7 )
break;
}
while ( v5 != 92 );
v8 = (_BYTE *)(v7 - v4);
v9 = v7 - v4 - 7;
result = 0xFFFFFFFFLL;
if ( v9 <= 0xC )
{
memcpy(fromcode, v4 + 8, (size_t)(v8 - 8));
v8[(_QWORD)fromcode - 8] = 0;
v10 = iconv_open("UTF-8", fromcode);
if ( v10 == (iconv_t)-1LL )
{
*((_QWORD *)fromcode + 23) = 0LL;
result = 0xFFFFFFFFLL;
if ( fromcode[181] )
return result;
}
else
{
*((_QWORD *)fromcode + 23) = v10;
}
goto LABEL_13;
}
}
return result;
}

original_code:
static inline enum po_error poparser_feed_hdr(struct po_parser *p, char* msg) {
 char *x, *y;
 if (p->first && msg) {
  if ((x = strstr(msg, "charset="))) {
   for (y = x; *y && *y != '\\' && !((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short int) _ISspace); y++);
   if ((uintptr_t)(y-x-7) > sizeof(p->hdr.charset))
    return -po_unsupported_charset;
   memcpy(p->hdr.charset, x+8, y-x-8);
   p->hdr.charset[y-x-8] = 0;
   p->cd = iconv_open("UTF-8", p->hdr.charset);
   if (p->cd == (iconv_t)-1) {
    p->cd = 0;
    if (p->strict) return -po_unsupported_charset;
   }
  }
  if ((x = strstr(msg, "nplurals="))) {
   p->hdr.nplurals = *(x+9) - '0';
  }
 }
 return po_success;
}

canonical_original_code:
static inline enum po_error poparser_feed_hdr(struct po_parser *p, char *msg) {
 char *x; char *y;
 if (p->first && msg) {
  if ((x = strstr(msg, "charset="))) {
   for (y = x; *y && *y != '\\' && !((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short) _ISspace); y++);
   if ((unsigned long)(y-x-7) > sizeof(p->hdr.charset))
    return -po_unsupported_charset;
   memcpy(p->hdr.charset, x+8, y-x-8);
   p->hdr.charset[y-x-8] = 0;
   p->cd = iconv_open("UTF-8", p->hdr.charset);
   if (p->cd == (iconv_t)-1) {
    p->cd = 0;
    if (p->strict) return -po_unsupported_charset;
   }
  }
  if ((x = strstr(msg, "nplurals="))) {
   p->hdr.nplurals = *(x+9) - '0';
  }
 }
 return po_success;
}

variable_types:
msg
char *

variable_types:
x
char *

variable_types:
y
char *

user_defined_types: enum po_error { po_success=0, po_unsupported_charset=1, po_failed_iconv=2, po_excepted_token=3, po_plurals_overflow=4, po_invalid_entry=5, po_internal=6, po_error_last=expr }

user_defined_types: struct po_header { char charset[12]; unsigned int nplurals; }

user_defined_types: struct po_message { char *ctxt; char *id; char *plural; char *str[6]; int sysdep; unsigned long ctxt_len; unsigned long id_len; unsigned long plural_len; unsigned long strlen[6]; int flags; }

user_defined_types: enum po_stage { ps_size=0, ps_parse=1, ps_max=expr }

user_defined_types: enum po_entry { po_ctxt=0, po_id=1, po_plural=2, po_str=3 }


original_code:
void poparser_init(struct po_parser *p, char* workbuf, size_t bufsize, poparser_callback cb, void* cbdata) {
 int cnt;
 memset(p, 0, sizeof(struct po_parser));
 p->buf = workbuf;
 p->bufsize = bufsize;
 p->cb = cb;
 p->cbdata = cbdata;
 p->hdr.nplurals = 6;
 p->max_ctxt_len = 1;
 p->max_id_len = 1;
 p->max_plural_len = 1;
 for (cnt = 0; cnt < 6; cnt++)
  p->max_strlen[cnt] = 1;
 p->strcnt = 0;
 p->first = 1;
}

canonical_original_code:
void poparser_init(struct po_parser *p, char *workbuf, unsigned long bufsize, int (*cb)(struct po_message *msg, void *user), void *cbdata) {
 int cnt;
 memset(p, 0, sizeof(struct po_parser));
 p->buf = workbuf;
 p->bufsize = bufsize;
 p->cb = cb;
 p->cbdata = cbdata;
 p->hdr.nplurals = 6;
 p->max_ctxt_len = 1;
 p->max_id_len = 1;
 p->max_plural_len = 1;
 for (cnt = 0; cnt < 6; cnt++)
  p->max_strlen[cnt] = 1;
 p->strcnt = 0;
 p->first = 1;
}

variable_types:
workbuf
char *

variable_types:
bufsize
unsigned long

variable_types: int (*)(struct po_message *msg, void *user)

variable_types:
cbdata
void *

variable_types: cnt int


decompiled_code:
__int64 __fastcall poparser_feed_line(char *fromcode, void *s1, size_t a3)
{
__int64 result; // rax
char v5; // dl
char *v6; // r12
char *v7; // rax
char *v8; // r14
char *v9; // rax
void *v10; // rdi
char *v11; // rdx
int v12; // er12
char *v13; // rbp
char *v14; // rax
const char *v15; // r14
char *v16; // rax
void *v17; // rdi
char *v18; // rdx
char *v19; // r13
const char **v20; // rbp
_DWORD *v21; // r12
unsigned int v22; // edx
char *v23; // r13
const char **v24; // rbp
_DWORD *v25; // r12
__int64 v26; // rsi
char *v27; // r13
const char **v28; // rbp
_DWORD *v29; // r12
__int64 v30; // rsi
__int64 v31; // rsi
const unsigned __int16 **v32; // rax
const unsigned __int16 *v33; // rcx
char v34; // dl
int v35; // eax
unsigned int v36; // edx
__int64 v37; // rsi
char *v38; // rdx
unsigned __int64 v39; // rcx
unsigned __int64 v40; // rdx
unsigned __int64 v41; // rdx
unsigned __int64 v42; // rdx
char *haystack; // [rsp+0h] [rbp-48h] BYREF
size_t outbytesleft; // [rsp+8h] [rbp-40h] BYREF
size_t inbytesleft; // [rsp+10h] [rbp-38h] BYREF
char *inbuf[6]; // [rsp+18h] [rbp-30h] BYREF

inbuf[0] = (char *)s1;
inbytesleft = a3;
result = 0LL;
if ( !a3 )
return result;
v5 = *(_BYTE *)s1;
if ( *(_BYTE *)s1 == 10 )
return result;
v6 = fromcode + 16;
if ( v5 == 35 )
{
if ( *((_DWORD *)fromcode + 48) == 3 )
{
result = poparser_clean((__int64)fromcode, (__int64)(fromcode + 16));
if ( (_DWORD)result )
return result;
}
result = 0LL;
if ( inbuf[0][1] != 44 )
return result;
v13 = inbuf[0] + 2;
haystack = inbuf[0] + 2;
if ( inbuf[0][2] )
{
do
{
v14 = strpbrk(v13, " ,\n");
v15 = v14;
if ( !v14 )
{
v12 = 0;
goto LABEL_104;
}
if ( v14 != v13 && !memcmp(v13, "fuzzy", v14 - v13) )
*((_DWORD *)fromcode + 42) |= 1u;
v13 = (char *)&v15[strspn(v15, " ,\n")];
haystack = v13;
}
while ( *v13 );
v12 = 0;
}
else
{
v12 = 0;
}
}
else if ( v5 == 34 )
{
haystack = (char *)s1 + 1;
v16 = strrchr((const char *)s1 + 1, 34);
if ( !v16 )
return 4294967293LL;
outbytesleft = v16 - ((_BYTE *)s1 + 1);
*v16 = 0;
v17 = (void *)*((_QWORD *)fromcode + 23);
if ( v17 )
{
inbuf[0] = (char *)s1 + 1;
inbytesleft = v16 - (_BYTE *)s1;
haystack = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = *((_QWORD *)fromcode + 35);
if ( iconv(v17, inbuf, &inbytesleft, &haystack, &outbytesleft) == -1LL )
return 4294967294LL;
result = 4294967294LL;
if ( inbytesleft )
return result;
v18 = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = haystack - v18;
haystack = v18;
}
v19 = haystack;
v20 = (const char **)sysdep_str;
v21 = &sysdep;
do
{
if ( strstr(v19, *v20) )
*((_DWORD *)fromcode + 22) |= *v21;
++v20;
++v21;
}
while ( v20 != (const char **)&sysdep_str[3] );
v22 = *((_DWORD *)fromcode + 48);
if ( v22 == 2 )
{
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(v19, *((_QWORD *)fromcode + 4) + *((_QWORD *)fromcode + 14), *((_QWORD *)fromcode + 27));
*((_QWORD *)fromcode + 14) += outbytesleft;
v12 = 3;
}
else if ( v22 > 2 )
{
result = 4294967291LL;
if ( v22 != 3 )
return result;
result = poparser_feed_hdr(fromcode, v19);
if ( (_DWORD)result )
return result;
v12 = *((_DWORD *)fromcode + 49) - 1;
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(
haystack,
*(_QWORD *)&fromcode[8 * v12 + 40] + *(_QWORD *)&fromcode[8 * v12 + 120],
*(_QWORD *)&fromcode[8 * v12 + 224]);
*(_QWORD *)&fromcode[8 * v12 + 120] += outbytesleft;
}
else if ( v22 )
{
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(v19, *((_QWORD *)fromcode + 3) + *((_QWORD *)fromcode + 13), *((_QWORD *)fromcode + 26));
*((_QWORD *)fromcode + 13) += outbytesleft;
v12 = 3;
}
else
{
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(v19, *((_QWORD *)fromcode + 2) + *((_QWORD *)fromcode + 12), *((_QWORD *)fromcode + 25));
*((_QWORD *)fromcode + 12) += outbytesleft;
v12 = 3;
}
}
else if ( !memcmp(s1, "msg", 3uLL) )
{
v7 = strchr((const char *)s1 + 3, 34);
if ( !v7 )
return 4294967293LL;
v8 = v7 + 1;
v9 = strrchr(v7 + 1, 34);
if ( !v9 )
return 4294967293LL;
haystack = v8;
outbytesleft = v9 - v8;
*v9 = 0;
v10 = (void *)*((_QWORD *)fromcode + 23);
if ( v10 )
{
inbuf[0] = v8;
inbytesleft = v9 - v8 + 1;
haystack = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = *((_QWORD *)fromcode + 35);
if ( iconv(v10, inbuf, &inbytesleft, &haystack, &outbytesleft) == -1LL )
return 4294967294LL;
result = 4294967294LL;
if ( inbytesleft )
return result;
v11 = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = haystack - v11;
haystack = v11;
}
if ( !memcmp((char *)s1 + 3, "ctxt", 4uLL) && ((*_ctype_b_loc())[*((char *)s1 + 7)] & 0x2000) != 0 )
{
result = poparser_clean((__int64)fromcode, (__int64)v6);
if ( (_DWORD)result )
return result;
result = 4294967291LL;
if ( *((_QWORD *)fromcode + 13) || *((_QWORD *)fromcode + 14) )
return result;
v23 = haystack;
v24 = (const char **)sysdep_str;
v25 = &sysdep;
do
{
if ( strstr(v23, *v24) )
*((_DWORD *)fromcode + 22) |= *v25;
++v24;
++v25;
}
while ( &sysdep_str[3] != (char **)v24 );
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v26 = *((_QWORD *)fromcode + 2);
if ( !v26 )
return 4294967290LL;
outbytesleft = unescape(v23, v26, *((_QWORD *)fromcode + 25));
}
*((_QWORD *)fromcode + 12) = outbytesleft;
*((_DWORD *)fromcode + 48) = 0;
v12 = 3;
}
else if ( !memcmp((char *)s1 + 3, "id", 2uLL) && ((*_ctype_b_loc())[*((char *)s1 + 5)] & 0x2000) != 0 )
{
result = poparser_clean((__int64)fromcode, (__int64)v6);
if ( (_DWORD)result )
return result;
result = 4294967291LL;
if ( *((_QWORD *)fromcode + 14) )
return result;
v27 = haystack;
v28 = (const char **)sysdep_str;
v29 = &sysdep;
do
{
if ( strstr(v27, *v28) )
*((_DWORD *)fromcode + 22) |= *v29;
++v28;
++v29;
}
while ( v28 != (const char **)&sysdep_str[3] );
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v30 = *((_QWORD *)fromcode + 3);
if ( !v30 )
return 4294967290LL;
outbytesleft = unescape(v27, v30, *((_QWORD *)fromcode + 26));
}
*((_QWORD *)fromcode + 13) = outbytesleft;
*((_DWORD *)fromcode + 48) = 1;
v12 = 3;
}
else
{
v12 = memcmp((char *)s1 + 3, "id_plural", 9uLL);
if ( v12 || ((*_ctype_b_loc())[*((char *)s1 + 12)] & 0x2000) == 0 )
{
v12 = memcmp((char *)s1 + 3, "str", 3uLL);
result = 4294967291LL;
if ( v12 || !*((_QWORD *)fromcode + 13) && !fromcode[180] )
return result;
v32 = _ctype_b_loc();
v33 = *v32;
v34 = *((_BYTE *)s1 + 6);
if ( ((*v32)[v34] & 0x2000) != 0 )
{
result = 4294967291LL;
if ( *((_DWORD *)fromcode + 49) || *((_QWORD *)fromcode + 14) )
return result;
*((_DWORD *)fromcode + 49) = 1;
}
else
{
result = 4294967293LL;
if ( v34 != 91 )
return result;
result = 4294967291LL;
if ( !*((_QWORD *)fromcode + 14) )
return result;
result = 4294967293LL;
if ( *((_BYTE *)s1 + 8) != 93 )
return result;
if ( (v33[*((char *)s1 + 9)] & 0x2000) == 0 )
return result;
v35 = *((char *)s1 + 7);
v12 = v35 - 48;
v36 = v35 - 47;
*((_DWORD *)fromcode + 49) = v35 - 47;
if ( fromcode[181] )
{
result = 4294967292LL;
if ( v36 > *((_DWORD *)fromcode + 3) )
return result;
}
}
result = poparser_feed_hdr(fromcode, haystack);
if ( (_DWORD)result )
return result;
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v37 = *(_QWORD *)&fromcode[8 * v12 + 40];
if ( !v37 )
return 4294967290LL;
outbytesleft = unescape(haystack, v37, *(_QWORD *)&fromcode[8 * v12 + 224]);
}
*(_QWORD *)&fromcode[8 * v12 + 120] = outbytesleft;
*((_DWORD *)fromcode + 48) = 3;
}
else
{
result = 4294967291LL;
if ( !*((_QWORD *)fromcode + 13) || *((_DWORD *)fromcode + 49) )
return result;
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v31 = *((_QWORD *)fromcode + 4);
if ( !v31 )
return 4294967290LL;
outbytesleft = unescape(haystack, v31, *((_QWORD *)fromcode + 27));
}
*((_QWORD *)fromcode + 14) = outbytesleft;
*((_DWORD *)fromcode + 48) = 2;
}
}
}
else
{
v12 = 0;
}
LABEL_104:
result = *((unsigned int *)fromcode + 44);
if ( (_DWORD)result )
return 0LL;
v38 = &fromcode[8 * v12];
v39 = *((_QWORD *)v38 + 15);
if ( *((_QWORD *)v38 + 28) < v39 )
*((_QWORD *)v38 + 28) = v39 + 1;
v40 = *((_QWORD *)fromcode + 14);
if ( *((_QWORD *)fromcode + 27) < v40 )
*((_QWORD *)fromcode + 27) = v40 + 1;
v41 = *((_QWORD *)fromcode + 13);
if ( *((_QWORD *)fromcode + 26) < v41 )
*((_QWORD *)fromcode + 26) = v41 + 1;
v42 = *((_QWORD *)fromcode + 12);
if ( *((_QWORD *)fromcode + 25) < v42 )
*((_QWORD *)fromcode + 25) = v42 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *fromcode, void *s1, size_t a3)
{
__int64 result; // rax
char v5; // dl
char *v6; // r12
char *v7; // rax
char *v8; // r14
char *v9; // rax
void *v10; // rdi
char *v11; // rdx
int v12; // er12
char *v13; // rbp
char *v14; // rax
const char *v15; // r14
char *v16; // rax
void *v17; // rdi
char *v18; // rdx
char *v19; // r13
const char **v20; // rbp
_DWORD *v21; // r12
unsigned int v22; // edx
char *v23; // r13
const char **v24; // rbp
_DWORD *v25; // r12
__int64 v26; // rsi
char *v27; // r13
const char **v28; // rbp
_DWORD *v29; // r12
__int64 v30; // rsi
__int64 v31; // rsi
const unsigned __int16 **v32; // rax
const unsigned __int16 *v33; // rcx
char v34; // dl
int v35; // eax
unsigned int v36; // edx
__int64 v37; // rsi
char *v38; // rdx
unsigned __int64 v39; // rcx
unsigned __int64 v40; // rdx
unsigned __int64 v41; // rdx
unsigned __int64 v42; // rdx
char *haystack; // [rsp+0h] [rbp-48h] BYREF
size_t outbytesleft; // [rsp+8h] [rbp-40h] BYREF
size_t inbytesleft; // [rsp+10h] [rbp-38h] BYREF
char *inbuf[6]; // [rsp+18h] [rbp-30h] BYREF

inbuf[0] = (char *)s1;
inbytesleft = a3;
result = 0LL;
if ( !a3 )
return result;
v5 = *(_BYTE *)s1;
if ( *(_BYTE *)s1 == 10 )
return result;
v6 = fromcode + 16;
if ( v5 == 35 )
{
if ( *((_DWORD *)fromcode + 48) == 3 )
{
result = func0((__int64)fromcode, (__int64)(fromcode + 16));
if ( (_DWORD)result )
return result;
}
result = 0LL;
if ( inbuf[0][1] != 44 )
return result;
v13 = inbuf[0] + 2;
haystack = inbuf[0] + 2;
if ( inbuf[0][2] )
{
do
{
v14 = strpbrk(v13, " ,\n");
v15 = v14;
if ( !v14 )
{
v12 = 0;
goto LABEL_104;
}
if ( v14 != v13 && !memcmp(v13, "fuzzy", v14 - v13) )
*((_DWORD *)fromcode + 42) |= 1u;
v13 = (char *)&v15[strspn(v15, " ,\n")];
haystack = v13;
}
while ( *v13 );
v12 = 0;
}
else
{
v12 = 0;
}
}
else if ( v5 == 34 )
{
haystack = (char *)s1 + 1;
v16 = strrchr((const char *)s1 + 1, 34);
if ( !v16 )
return 4294967293LL;
outbytesleft = v16 - ((_BYTE *)s1 + 1);
*v16 = 0;
v17 = (void *)*((_QWORD *)fromcode + 23);
if ( v17 )
{
inbuf[0] = (char *)s1 + 1;
inbytesleft = v16 - (_BYTE *)s1;
haystack = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = *((_QWORD *)fromcode + 35);
if ( iconv(v17, inbuf, &inbytesleft, &haystack, &outbytesleft) == -1LL )
return 4294967294LL;
result = 4294967294LL;
if ( inbytesleft )
return result;
v18 = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = haystack - v18;
haystack = v18;
}
v19 = haystack;
v20 = (const char **)sysdep_str;
v21 = &sysdep;
do
{
if ( strstr(v19, *v20) )
*((_DWORD *)fromcode + 22) |= *v21;
++v20;
++v21;
}
while ( v20 != (const char **)&sysdep_str[3] );
v22 = *((_DWORD *)fromcode + 48);
if ( v22 == 2 )
{
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(v19, *((_QWORD *)fromcode + 4) + *((_QWORD *)fromcode + 14), *((_QWORD *)fromcode + 27));
*((_QWORD *)fromcode + 14) += outbytesleft;
v12 = 3;
}
else if ( v22 > 2 )
{
result = 4294967291LL;
if ( v22 != 3 )
return result;
result = func1(fromcode, v19);
if ( (_DWORD)result )
return result;
v12 = *((_DWORD *)fromcode + 49) - 1;
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(
haystack,
*(_QWORD *)&fromcode[8 * v12 + 40] + *(_QWORD *)&fromcode[8 * v12 + 120],
*(_QWORD *)&fromcode[8 * v12 + 224]);
*(_QWORD *)&fromcode[8 * v12 + 120] += outbytesleft;
}
else if ( v22 )
{
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(v19, *((_QWORD *)fromcode + 3) + *((_QWORD *)fromcode + 13), *((_QWORD *)fromcode + 26));
*((_QWORD *)fromcode + 13) += outbytesleft;
v12 = 3;
}
else
{
if ( *((_DWORD *)fromcode + 44) == 1 )
outbytesleft = unescape(v19, *((_QWORD *)fromcode + 2) + *((_QWORD *)fromcode + 12), *((_QWORD *)fromcode + 25));
*((_QWORD *)fromcode + 12) += outbytesleft;
v12 = 3;
}
}
else if ( !memcmp(s1, "msg", 3uLL) )
{
v7 = strchr((const char *)s1 + 3, 34);
if ( !v7 )
return 4294967293LL;
v8 = v7 + 1;
v9 = strrchr(v7 + 1, 34);
if ( !v9 )
return 4294967293LL;
haystack = v8;
outbytesleft = v9 - v8;
*v9 = 0;
v10 = (void *)*((_QWORD *)fromcode + 23);
if ( v10 )
{
inbuf[0] = v8;
inbytesleft = v9 - v8 + 1;
haystack = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = *((_QWORD *)fromcode + 35);
if ( iconv(v10, inbuf, &inbytesleft, &haystack, &outbytesleft) == -1LL )
return 4294967294LL;
result = 4294967294LL;
if ( inbytesleft )
return result;
v11 = (char *)*((_QWORD *)fromcode + 34);
outbytesleft = haystack - v11;
haystack = v11;
}
if ( !memcmp((char *)s1 + 3, "ctxt", 4uLL) && ((*_ctype_b_loc())[*((char *)s1 + 7)] & 0x2000) != 0 )
{
result = func0((__int64)fromcode, (__int64)v6);
if ( (_DWORD)result )
return result;
result = 4294967291LL;
if ( *((_QWORD *)fromcode + 13) || *((_QWORD *)fromcode + 14) )
return result;
v23 = haystack;
v24 = (const char **)sysdep_str;
v25 = &sysdep;
do
{
if ( strstr(v23, *v24) )
*((_DWORD *)fromcode + 22) |= *v25;
++v24;
++v25;
}
while ( &sysdep_str[3] != (char **)v24 );
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v26 = *((_QWORD *)fromcode + 2);
if ( !v26 )
return 4294967290LL;
outbytesleft = unescape(v23, v26, *((_QWORD *)fromcode + 25));
}
*((_QWORD *)fromcode + 12) = outbytesleft;
*((_DWORD *)fromcode + 48) = 0;
v12 = 3;
}
else if ( !memcmp((char *)s1 + 3, "id", 2uLL) && ((*_ctype_b_loc())[*((char *)s1 + 5)] & 0x2000) != 0 )
{
result = func0((__int64)fromcode, (__int64)v6);
if ( (_DWORD)result )
return result;
result = 4294967291LL;
if ( *((_QWORD *)fromcode + 14) )
return result;
v27 = haystack;
v28 = (const char **)sysdep_str;
v29 = &sysdep;
do
{
if ( strstr(v27, *v28) )
*((_DWORD *)fromcode + 22) |= *v29;
++v28;
++v29;
}
while ( v28 != (const char **)&sysdep_str[3] );
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v30 = *((_QWORD *)fromcode + 3);
if ( !v30 )
return 4294967290LL;
outbytesleft = unescape(v27, v30, *((_QWORD *)fromcode + 26));
}
*((_QWORD *)fromcode + 13) = outbytesleft;
*((_DWORD *)fromcode + 48) = 1;
v12 = 3;
}
else
{
v12 = memcmp((char *)s1 + 3, "id_plural", 9uLL);
if ( v12 || ((*_ctype_b_loc())[*((char *)s1 + 12)] & 0x2000) == 0 )
{
v12 = memcmp((char *)s1 + 3, "str", 3uLL);
result = 4294967291LL;
if ( v12 || !*((_QWORD *)fromcode + 13) && !fromcode[180] )
return result;
v32 = _ctype_b_loc();
v33 = *v32;
v34 = *((_BYTE *)s1 + 6);
if ( ((*v32)[v34] & 0x2000) != 0 )
{
result = 4294967291LL;
if ( *((_DWORD *)fromcode + 49) || *((_QWORD *)fromcode + 14) )
return result;
*((_DWORD *)fromcode + 49) = 1;
}
else
{
result = 4294967293LL;
if ( v34 != 91 )
return result;
result = 4294967291LL;
if ( !*((_QWORD *)fromcode + 14) )
return result;
result = 4294967293LL;
if ( *((_BYTE *)s1 + 8) != 93 )
return result;
if ( (v33[*((char *)s1 + 9)] & 0x2000) == 0 )
return result;
v35 = *((char *)s1 + 7);
v12 = v35 - 48;
v36 = v35 - 47;
*((_DWORD *)fromcode + 49) = v35 - 47;
if ( fromcode[181] )
{
result = 4294967292LL;
if ( v36 > *((_DWORD *)fromcode + 3) )
return result;
}
}
result = func1(fromcode, haystack);
if ( (_DWORD)result )
return result;
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v37 = *(_QWORD *)&fromcode[8 * v12 + 40];
if ( !v37 )
return 4294967290LL;
outbytesleft = unescape(haystack, v37, *(_QWORD *)&fromcode[8 * v12 + 224]);
}
*(_QWORD *)&fromcode[8 * v12 + 120] = outbytesleft;
*((_DWORD *)fromcode + 48) = 3;
}
else
{
result = 4294967291LL;
if ( !*((_QWORD *)fromcode + 13) || *((_DWORD *)fromcode + 49) )
return result;
if ( *((_DWORD *)fromcode + 44) == 1 )
{
v31 = *((_QWORD *)fromcode + 4);
if ( !v31 )
return 4294967290LL;
outbytesleft = unescape(haystack, v31, *((_QWORD *)fromcode + 27));
}
*((_QWORD *)fromcode + 14) = outbytesleft;
*((_DWORD *)fromcode + 48) = 2;
}
}
}
else
{
v12 = 0;
}
LABEL_104:
result = *((unsigned int *)fromcode + 44);
if ( (_DWORD)result )
return 0LL;
v38 = &fromcode[8 * v12];
v39 = *((_QWORD *)v38 + 15);
if ( *((_QWORD *)v38 + 28) < v39 )
*((_QWORD *)v38 + 28) = v39 + 1;
v40 = *((_QWORD *)fromcode + 14);
if ( *((_QWORD *)fromcode + 27) < v40 )
*((_QWORD *)fromcode + 27) = v40 + 1;
v41 = *((_QWORD *)fromcode + 13);
if ( *((_QWORD *)fromcode + 26) < v41 )
*((_QWORD *)fromcode + 26) = v41 + 1;
v42 = *((_QWORD *)fromcode + 12);
if ( *((_QWORD *)fromcode + 25) < v42 )
*((_QWORD *)fromcode + 25) = v42 + 1;
return result;
}

original_code:
enum po_error poparser_feed_line(struct po_parser *p, char* in, size_t in_len) {
 char *line = in;
 size_t line_len = in_len;
 po_message_t msg = &p->msg;
 int cnt = 0;
 enum po_error t;
 size_t len;
 char *x, *y, *z;
 if (line_len == 0 || line[0] == '\n') {
  return po_success;
 } else if (line[0] == '#') {
  if (p->previous == po_str) {
   if ( (t = poparser_clean(p, msg)) != po_success)
    return t;
  }
  switch (line[1]) {
  case ',':
   x = &line[2];
   while (*x && (y = strpbrk(x, " ,\n"))) {
    if (y != x && !memcmp(x, "fuzzy", y-x)) {
     msg->flags |= 1u;
    }
    x = y + strspn(y, " ,\n");
   }
   break;
  case '.':
  case ':':
  case '|':
  default:
   return po_success;
  }
 } else if (line[0] == '"') {
  if ( (y = strrchr(x = &line[1], '"')) == ((void *)0))
   return -po_excepted_token;
  len = y - x;
  *y = 0;
  if (p->cd) {
   line = x;
   line_len = len + 1;
   x = p->buf;
   len = p->bufsize;
   if (iconv(p->cd, &line, &line_len, &x, &len) == (size_t)-1)
    return -po_failed_iconv;
   if (line_len != 0)
    return -po_failed_iconv;
   len = x - p->buf;
   x = p->buf;
  }
  for (cnt = 0; cnt < st_max; cnt++) {
   if (strstr(x, sysdep_str[cnt])) {
    msg->sysdep |= sysdep[cnt];
   }
  }
  switch (p->previous) {
  case po_str:
   if ((t = poparser_feed_hdr(p, x)) != po_success) {
    return t;
   }
   cnt = p->strcnt - 1;
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->str[cnt][msg->strlen[cnt]], p->max_strlen[cnt]);
   }
   msg->strlen[cnt] += len;
   break;
  case po_plural:
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->plural[msg->plural_len], p->max_plural_len);
   }
   msg->plural_len += len;
   break;
  case po_id:
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->id[msg->id_len], p->max_id_len);
   }
   msg->id_len += len;
   break;
  case po_ctxt:
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->ctxt[msg->ctxt_len], p->max_ctxt_len);
   }
   msg->ctxt_len += len;
   break;
  default:
   return -po_invalid_entry;
  }
 } else if ((z = (memcmp(line, "msg", sizeof("msg") - 1) ? ((void *)0) : (line + (sizeof("msg") - 1))))) {
  if ( (x = strchr(z, '"')) == ((void *)0))
   return -po_excepted_token;
  if ( (y = strrchr(x+1, '"')) == ((void *)0))
   return -po_excepted_token;
  len = y - ++x;
  *y = 0;
  if (p->cd) {
   line = x;
   line_len = len + 1;
   x = p->buf;
   len = p->bufsize;
   if (iconv(p->cd, &line, &line_len, &x, &len) == (size_t)-1)
    return -po_failed_iconv;
   if (line_len != 0)
    return -po_failed_iconv;
   len = x - p->buf;
   x = p->buf;
  }
  if ((y = (memcmp(z, "ctxt", sizeof("ctxt") - 1) ? ((void *)0) : (z + (sizeof("ctxt") - 1)))) && ((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short int) _ISspace)) {
   if ( (t = poparser_clean(p, msg)) != po_success)
    return t;
   if (msg->id_len || msg->plural_len)
    return -po_invalid_entry;
   for (cnt = 0; cnt < st_max; cnt++) {
    if (strstr(x, sysdep_str[cnt])) {
     msg->sysdep |= sysdep[cnt];
    }
   }
   if (p->stage == ps_parse) {
    if (msg->ctxt == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->ctxt, p->max_ctxt_len);
   }
   msg->ctxt_len = len;
   p->previous = po_ctxt;
  } else if ((y = (memcmp(z, "id", sizeof("id") - 1) ? ((void *)0) : (z + (sizeof("id") - 1)))) && ((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short int) _ISspace)) {
   if ( (t = poparser_clean(p, msg)) != po_success)
    return t;
   if (msg->plural_len)
    return -po_invalid_entry;
   for (cnt = 0; cnt < st_max; cnt++) {
    if (strstr(x, sysdep_str[cnt])) {
     msg->sysdep |= sysdep[cnt];
    }
   }
   if (p->stage == ps_parse) {
    if (msg->id == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->id, p->max_id_len);
   }
   msg->id_len = len;
   p->previous = po_id;
  } else if ((y = (memcmp(z, "id_plural", sizeof("id_plural") - 1) ? ((void *)0) : (z + (sizeof("id_plural") - 1)))) && ((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short int) _ISspace)) {
   if (!msg->id_len || p->strcnt)
    return -po_invalid_entry;
   if (p->stage == ps_parse) {
    if (msg->plural == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->plural, p->max_plural_len);
   }
   msg->plural_len = len;
   p->previous = po_plural;
  } else if ((y = (memcmp(z, "str", sizeof("str") - 1) ? ((void *)0) : (z + (sizeof("str") - 1))))) {
   if (!msg->id_len && !p->first)
    return -po_invalid_entry;
   if (((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short int) _ISspace)) {
    if (p->strcnt || msg->plural_len)
     return -po_invalid_entry;
    cnt = (p->strcnt = 1) - 1;
   } else if (*y == '[') {
    if (!msg->plural_len)
     return -po_invalid_entry;
    if (y[2] != ']' || !((*__ctype_b_loc ())[(int) ((y[3]))] & (unsigned short int) _ISspace)) return -po_excepted_token;
    p->strcnt = (cnt = y[1] - '0') + 1;
    if (p->strict && p->strcnt > p->hdr.nplurals) {
     return -po_plurals_overflow;
    }
   } else {
    return -po_excepted_token;
   }
   if ((t = poparser_feed_hdr(p, x)) != po_success) {
    return t;
   }
   if (p->stage == ps_parse) {
    if (msg->str[cnt] == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->str[cnt], p->max_strlen[cnt]);
   }
   msg->strlen[cnt] = len;
   p->previous = po_str;
  } else {
   return -po_invalid_entry;
  }
 }
 if (p->stage == ps_size) {
  if (p->max_strlen[cnt] < msg->strlen[cnt])
   p->max_strlen[cnt] = msg->strlen[cnt] + 1;
  if (p->max_plural_len < msg->plural_len)
   p->max_plural_len = msg->plural_len + 1;
  if (p->max_id_len < msg->id_len)
   p->max_id_len = msg->id_len + 1;
  if (p->max_ctxt_len < msg->ctxt_len)
   p->max_ctxt_len = msg->ctxt_len + 1;
 }
 return po_success;
}

canonical_original_code:
enum po_error poparser_feed_line(struct po_parser *p, char *in, unsigned long in_len) {
 char *line = in;
 unsigned long line_len = in_len;
 struct po_message *msg = &p->msg;
 int cnt = 0;
 enum po_error t;
 unsigned long len;
 char *x; char *y; char *z;
 if (line_len == 0 || line[0] == '\n') {
  return po_success;
 } else if (line[0] == '#') {
  if (p->previous == po_str) {
   if ( (t = poparser_clean(p, msg)) != po_success)
    return t;
  }
  switch (line[1]) {
  case ',':
   x = &line[2];
   while (*x && (y = strpbrk(x, " ,\n"))) {
    if (y != x && !memcmp(x, "fuzzy", y-x)) {
     msg->flags |= 1u;
    }
    x = y + strspn(y, " ,\n");
   }
   break;
  case '.':
  case ':':
  case '|':
  default:
   return po_success;
  }
 } else if (line[0] == '"') {
  if ( (y = strrchr(x = &line[1], '"')) == ((void *)0))
   return -po_excepted_token;
  len = y - x;
  *y = 0;
  if (p->cd) {
   line = x;
   line_len = len + 1;
   x = p->buf;
   len = p->bufsize;
   if (iconv(p->cd, &line, &line_len, &x, &len) == (unsigned long)-1)
    return -po_failed_iconv;
   if (line_len != 0)
    return -po_failed_iconv;
   len = x - p->buf;
   x = p->buf;
  }
  for (cnt = 0; cnt < st_max; cnt++) {
   if (strstr(x, sysdep_str[cnt])) {
    msg->sysdep |= sysdep[cnt];
   }
  }
  switch (p->previous) {
  case po_str:
   if ((t = poparser_feed_hdr(p, x)) != po_success) {
    return t;
   }
   cnt = p->strcnt - 1;
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->str[cnt][msg->strlen[cnt]], p->max_strlen[cnt]);
   }
   msg->strlen[cnt] += len;
   break;
  case po_plural:
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->plural[msg->plural_len], p->max_plural_len);
   }
   msg->plural_len += len;
   break;
  case po_id:
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->id[msg->id_len], p->max_id_len);
   }
   msg->id_len += len;
   break;
  case po_ctxt:
   if (p->stage == ps_parse) {
    len = unescape(x, &msg->ctxt[msg->ctxt_len], p->max_ctxt_len);
   }
   msg->ctxt_len += len;
   break;
  default:
   return -po_invalid_entry;
  }
 } else if ((z = (memcmp(line, "msg", sizeof("msg") - 1) ? ((void *)0) : (line + (sizeof("msg") - 1))))) {
  if ( (x = strchr(z, '"')) == ((void *)0))
   return -po_excepted_token;
  if ( (y = strrchr(x+1, '"')) == ((void *)0))
   return -po_excepted_token;
  len = y - ++x;
  *y = 0;
  if (p->cd) {
   line = x;
   line_len = len + 1;
   x = p->buf;
   len = p->bufsize;
   if (iconv(p->cd, &line, &line_len, &x, &len) == (unsigned long)-1)
    return -po_failed_iconv;
   if (line_len != 0)
    return -po_failed_iconv;
   len = x - p->buf;
   x = p->buf;
  }
  if ((y = (memcmp(z, "ctxt", sizeof("ctxt") - 1) ? ((void *)0) : (z + (sizeof("ctxt") - 1)))) && ((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short) _ISspace)) {
   if ( (t = poparser_clean(p, msg)) != po_success)
    return t;
   if (msg->id_len || msg->plural_len)
    return -po_invalid_entry;
   for (cnt = 0; cnt < st_max; cnt++) {
    if (strstr(x, sysdep_str[cnt])) {
     msg->sysdep |= sysdep[cnt];
    }
   }
   if (p->stage == ps_parse) {
    if (msg->ctxt == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->ctxt, p->max_ctxt_len);
   }
   msg->ctxt_len = len;
   p->previous = po_ctxt;
  } else if ((y = (memcmp(z, "id", sizeof("id") - 1) ? ((void *)0) : (z + (sizeof("id") - 1)))) && ((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short) _ISspace)) {
   if ( (t = poparser_clean(p, msg)) != po_success)
    return t;
   if (msg->plural_len)
    return -po_invalid_entry;
   for (cnt = 0; cnt < st_max; cnt++) {
    if (strstr(x, sysdep_str[cnt])) {
     msg->sysdep |= sysdep[cnt];
    }
   }
   if (p->stage == ps_parse) {
    if (msg->id == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->id, p->max_id_len);
   }
   msg->id_len = len;
   p->previous = po_id;
  } else if ((y = (memcmp(z, "id_plural", sizeof("id_plural") - 1) ? ((void *)0) : (z + (sizeof("id_plural") - 1)))) && ((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short) _ISspace)) {
   if (!msg->id_len || p->strcnt)
    return -po_invalid_entry;
   if (p->stage == ps_parse) {
    if (msg->plural == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->plural, p->max_plural_len);
   }
   msg->plural_len = len;
   p->previous = po_plural;
  } else if ((y = (memcmp(z, "str", sizeof("str") - 1) ? ((void *)0) : (z + (sizeof("str") - 1))))) {
   if (!msg->id_len && !p->first)
    return -po_invalid_entry;
   if (((*__ctype_b_loc ())[(int) ((*y))] & (unsigned short) _ISspace)) {
    if (p->strcnt || msg->plural_len)
     return -po_invalid_entry;
    cnt = (p->strcnt = 1) - 1;
   } else if (*y == '[') {
    if (!msg->plural_len)
     return -po_invalid_entry;
    if (y[2] != ']' || !((*__ctype_b_loc ())[(int) ((y[3]))] & (unsigned short) _ISspace)) return -po_excepted_token;
    p->strcnt = (cnt = y[1] - '0') + 1;
    if (p->strict && p->strcnt > p->hdr.nplurals) {
     return -po_plurals_overflow;
    }
   } else {
    return -po_excepted_token;
   }
   if ((t = poparser_feed_hdr(p, x)) != po_success) {
    return t;
   }
   if (p->stage == ps_parse) {
    if (msg->str[cnt] == ((void *)0)) {
     return -po_internal;
    }
    len = unescape(x, msg->str[cnt], p->max_strlen[cnt]);
   }
   msg->strlen[cnt] = len;
   p->previous = po_str;
  } else {
   return -po_invalid_entry;
  }
 }
 if (p->stage == ps_size) {
  if (p->max_strlen[cnt] < msg->strlen[cnt])
   p->max_strlen[cnt] = msg->strlen[cnt] + 1;
  if (p->max_plural_len < msg->plural_len)
   p->max_plural_len = msg->plural_len + 1;
  if (p->max_id_len < msg->id_len)
   p->max_id_len = msg->id_len + 1;
  if (p->max_ctxt_len < msg->ctxt_len)
   p->max_ctxt_len = msg->ctxt_len + 1;
 }
 return po_success;
}

variable_types:
in
char *

variable_types:
line
char *

variable_types: struct po_message { char *ctxt; char *id; char *plural; char *str[6]; int sysdep; unsigned long ctxt_len; unsigned long id_len; unsigned long plural_len; unsigned long strlen[6]; int flags; } *

variable_types: enum po_error { po_success=0, po_unsupported_charset=1, po_failed_iconv=2, po_excepted_token=3, po_plurals_overflow=4, po_invalid_entry=5, po_internal=6, po_error_last=expr }

variable_types:
len
unsigned long

variable_types:
z
char *


original_code:
enum po_error poparser_finish(struct po_parser *p) {
 size_t len;
 int cnt;
 enum po_error t;
 po_message_t msg = &p->msg;
 if (p->stage == ps_size) {
  if ( (t = poparser_clean(p, msg)) != po_success)
   return t;
  len = p->max_ctxt_len;
  len += p->max_id_len;
  len += p->max_plural_len;
  for (cnt = 0; cnt < 6; cnt++)
   len += p->max_strlen[cnt];
  memset(msg, 0, sizeof(struct po_message));
  msg->ctxt = (char*)malloc(len);
  msg->id = msg->ctxt + p->max_ctxt_len;
  msg->plural = msg->id + p->max_id_len;
  msg->str[0] = msg->plural + p->max_plural_len;
  for (cnt = 1; cnt < 6; cnt++)
   msg->str[cnt] = msg->str[cnt-1] + p->max_strlen[cnt-1];
  p->hdr.nplurals = 2;
  p->first = 1;
 } else {
  if ( (t = poparser_clean(p, msg)) != po_success)
   return t;
  if (msg->ctxt) free(msg->ctxt);
  if (p->cd) iconv_close(p->cd);
 }
 if (p->stage < ps_parse) p->stage++;
 return po_success;
}

canonical_original_code:
enum po_error poparser_finish(struct po_parser *p) {
 unsigned long len;
 int cnt;
 enum po_error t;
 struct po_message *msg = &p->msg;
 if (p->stage == ps_size) {
  if ( (t = poparser_clean(p, msg)) != po_success)
   return t;
  len = p->max_ctxt_len;
  len += p->max_id_len;
  len += p->max_plural_len;
  for (cnt = 0; cnt < 6; cnt++)
   len += p->max_strlen[cnt];
  memset(msg, 0, sizeof(struct po_message));
  msg->ctxt = (char *)malloc(len);
  msg->id = msg->ctxt + p->max_ctxt_len;
  msg->plural = msg->id + p->max_id_len;
  msg->str[0] = msg->plural + p->max_plural_len;
  for (cnt = 1; cnt < 6; cnt++)
   msg->str[cnt] = msg->str[cnt-1] + p->max_strlen[cnt-1];
  p->hdr.nplurals = 2;
  p->first = 1;
 } else {
  if ( (t = poparser_clean(p, msg)) != po_success)
   return t;
  if (msg->ctxt) free(msg->ctxt);
  if (p->cd) iconv_close(p->cd);
 }
 if (p->stage < ps_parse) p->stage++;
 return po_success;
}


decompiled_code:
__int64 __fastcall poparser_sysdep(char *s, void *dest, int a3)
{
char *v4; // r14
__int64 v5; // rbp
const char *v6; // r13
size_t v7; // rbx
char *v8; // rax
char *v9; // r12
const char *v10; // rbp
size_t v11; // rax
size_t v12; // r12
size_t v13; // rax
size_t v14; // rbp
__int64 v16; // [rsp+18h] [rbp-40h]

v4 = (char *)dest;
v16 = a3;
LABEL_6:
while ( 1 )
{
v8 = strchr(s, 37);
if ( !v8 )
break;
v9 = v8 + 1;
if ( dest )
memcpy(v4, s, v9 - s);
v4 += v9 - s;
v5 = 0LL;
while ( 1 )
{
v6 = sysdep_str[v5];
v7 = strlen(v6);
if ( !strncmp(v9, v6, v7) )
break;
if ( ++v5 == 3 )
{
s = v9;
goto LABEL_6;
}
}
s = &v9[v7];
v10 = (&sysdep_repl[3 * (int)v5])[v16];
v11 = strlen(v10);
v12 = v11;
if ( dest )
memcpy(v4, v10, v11);
v4 += v12;
}
v13 = strlen(s);
v14 = v13;
if ( dest )
memcpy(v4, s, v13 + 1);
return &v4[v14] - (_BYTE *)dest;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, void *dest, int a3)
{
char *v4; // r14
__int64 v5; // rbp
const char *v6; // r13
size_t v7; // rbx
char *v8; // rax
char *v9; // r12
const char *v10; // rbp
size_t v11; // rax
size_t v12; // r12
size_t v13; // rax
size_t v14; // rbp
__int64 v16; // [rsp+18h] [rbp-40h]

v4 = (char *)dest;
v16 = a3;
LABEL_6:
while ( 1 )
{
v8 = strchr(s, 37);
if ( !v8 )
break;
v9 = v8 + 1;
if ( dest )
memcpy(v4, s, v9 - s);
v4 += v9 - s;
v5 = 0LL;
while ( 1 )
{
v6 = sysdep_str[v5];
v7 = strlen(v6);
if ( !strncmp(v9, v6, v7) )
break;
if ( ++v5 == 3 )
{
s = v9;
goto LABEL_6;
}
}
s = &v9[v7];
v10 = (&sysdep_repl[3 * (int)v5])[v16];
v11 = strlen(v10);
v12 = v11;
if ( dest )
memcpy(v4, v10, v11);
v4 += v12;
}
v13 = strlen(s);
v14 = v13;
if ( dest )
memcpy(v4, s, v13 + 1);
return &v4[v14] - (_BYTE *)dest;
}

original_code:
size_t poparser_sysdep(const char *in, char *out, int num) {
 const char *x, *y, *outs;
 size_t m;
 int n;
 outs = out;
 x = in;
 while ((y = strchr(x, '%'))) {
  y++;
  if (outs)
   memcpy(out, x, y-x);
  out += y-x;
  x = y;
  for (n=0; n < st_max; n++) {
   m = strlen(sysdep_str[n]);
   if (!strncmp(y, sysdep_str[n], m)) {
    x = y + m;
    y = sysdep_repl[n][num];
    m = strlen(y);
    if (outs)
     memcpy(out, y, m);
    out += m;
    break;
   }
  }
 }
 m = strlen(x);
 if (outs)
  memcpy(out, x, m+1);
 out += m;
 return out - outs;
}

canonical_original_code:
unsigned long poparser_sysdep(char *in, char *out, int num) {
 char *x; char *y; char *outs;
 unsigned long m;
 int n;
 outs = out;
 x = in;
 while ((y = strchr(x, '%'))) {
  y++;
  if (outs)
   memcpy(out, x, y-x);
  out += y-x;
  x = y;
  for (n=0; n < st_max; n++) {
   m = strlen(sysdep_str[n]);
   if (!strncmp(y, sysdep_str[n], m)) {
    x = y + m;
    y = sysdep_repl[n][num];
    m = strlen(y);
    if (outs)
     memcpy(out, y, m);
    out += m;
    break;
   }
  }
 }
 m = strlen(x);
 if (outs)
  memcpy(out, x, m+1);
 out += m;
 return out - outs;
}

variable_types:
out
char *

variable_types: num int

variable_types:
outs
char *

variable_types:
m
unsigned long

variable_types: n int

return_type: unsigned long


decompiled_code:
int __fastcall strtbl_cmp(const void *a1, const void *a2)
{
return strcmp(
(const char *)(*((unsigned int *)a1 + 1) + *(_QWORD *)(cb_for_qsort + 40)),
(const char *)(*(_QWORD *)(cb_for_qsort + 40) + *((unsigned int *)a2 + 1)));
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(
(const char *)(*((unsigned int *)a1 + 1) + *(_QWORD *)(cb_for_qsort + 40)),
(const char *)(*(_QWORD *)(cb_for_qsort + 40) + *((unsigned int *)a2 + 1)));
}

original_code:
int strtbl_cmp(const void *a_, const void *b_) {
 const struct strmap *a = a_, *b = b_;
 return strcmp(cb_for_qsort->buf[0] + a->str.off, cb_for_qsort->buf[0] + b->str.off);
}

canonical_original_code:
int strtbl_cmp(void *a_, void *b_) {
 struct strmap *a = a_; struct strmap *b = b_;
 return strcmp(cb_for_qsort->buf[0] + a->str.off, cb_for_qsort->buf[0] + b->str.off);
}

variable_types: struct strmap { struct strtbl { unsigned int len; } str; struct strtbl trans; } *

user_defined_types: struct strmap { struct strtbl str; struct strtbl trans; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // ebx
__int64 v5; // r13
const char *v6; // rbp
FILE *v7; // rsi
FILE *v8; // rdi
size_t v9; // rdx
const char *v11; // [rsp+8h] [rbp-2060h]
char *filename; // [rsp+10h] [rbp-2058h]
unsigned int v13; // [rsp+18h] [rbp-2050h]
char v14; // [rsp+1Fh] [rbp-2049h]
char ptr[4096]; // [rsp+20h] [rbp-2048h] BYREF
char s[4096]; // [rsp+1020h] [rbp-1048h] BYREF
FILE *stream; // [rsp+2020h] [rbp-48h] BYREF
FILE *v18[8]; // [rsp+2028h] [rbp-40h] BYREF

if ( argc == 1 )
{
syntax();
return 1;
}
v18[0] = 0LL;
stream = 0LL;
if ( argc <= 1 )
{
filename = 0LL;
v14 = 0;
goto LABEL_102;
}
filename = 0LL;
v11 = 0LL;
v14 = 0;
v13 = 0;
for ( i = 1; i < argc; ++i )
{
v5 = i;
v6 = argv[v5];
if ( *v6 != 45 )
goto LABEL_64;
if ( v6[1] == 45 )
{
if ( strcmp(v6 + 2, "template")
&& strcmp(v6 + 2, "strict")
&& strcmp(v6 + 2, "properties-input")
&& strcmp(v6 + 2, "stringtable-input")
&& strcmp(v6 + 2, "use-fuzzy")
&& memcmp(v6 + 2, "alignment=", 0xAuLL)
&& strcmp(v6 + 2, "check-format")
&& strcmp(v6 + 2, "check-header")
&& strcmp(v6 + 2, "check-domain")
&& strcmp(v6 + 2, "check-compatibility")
&& strcmp(v6 + 2, "check-accelerators")
&& strcmp(v6 + 2, "no-hash")
&& strcmp(v6 + 2, "verbose")
&& strcmp(v6 + 2, "statistics")
&& memcmp(v6 + 2, "keyword=", 8uLL)
&& memcmp(v6 + 2, "check-accelerators=", 0x13uLL)
&& memcmp(v6 + 2, "resource=", 9uLL) )
{
if ( !strcmp(v6 + 2, "java") )
{
v13 = 1;
}
else if ( !strcmp(v6 + 2, "java2") )
{
v13 = 2;
}
else if ( !strcmp(v6 + 2, "csharp") )
{
v13 = 3;
}
else if ( !strcmp(v6 + 2, "csharp-resources") )
{
v13 = 4;
}
else if ( !strcmp(v6 + 2, "tcl") )
{
v13 = 5;
}
else if ( !strcmp(v6 + 2, "qt") )
{
v13 = 6;
}
else if ( !strcmp(v6 + 2, "desktop") )
{
v13 = 7;
}
else if ( !strcmp(v6 + 2, "xml") )
{
v13 = 8;
}
else
{
if ( !strcmp(v6 + 2, "keyword") )
{
++i;
continue;
}
if ( !memcmp(v6 + 2, "locale=", 7uLL) )
{
v11 = v6 + 9;
continue;
}
if ( strcmp(v6 + 2, "check") )
{
if ( !memcmp(v6 + 2, "template=", 9uLL) )
{
set_file(0, v6 + 11, &stream);
v11 = 0LL;
continue;
}
if ( !memcmp(v6 + 2, "output-file=", 0xCuLL) )
{
set_file(1, v6 + 14, v18);
v11 = 0LL;
continue;
}
if ( !memcmp(v6 + 2, "output=", 7uLL) )
{
set_file(1, v6 + 9, v18);
v11 = 0LL;
continue;
}
if ( !strcmp(v6 + 2, "version") )
{
LABEL_59:
v4 = 0;
version();
return v4;
}
if ( !strcmp(v6 + 2, "help") )
{
v4 = 0;
syntax();
return v4;
}
v11 = 0LL;
LABEL_64:
set_file(0, v6, &stream);
continue;
}
v11 = 0LL;
v14 = 1;
}
}
}
else
{
if ( !strcmp(v6 + 1, LC40) )
{
++i;
set_file(1, argv[v5 + 1], v18);
continue;
}
if ( strcmp(v6 + 1, "j")
&& strcmp(v6 + 1, "r")
&& strcmp(v6 + 1, "P")
&& strcmp(v6 + 1, "f")
&& strcmp(v6 + 1, "a")
&& strcmp(v6 + 1, "v")
&& strcmp(v6 + 1, "C") )
{
if ( !strcmp(v6 + 1, "c") )
{
v14 = 1;
}
else
{
if ( !strcmp(v6 + 1, "V") )
goto LABEL_59;
if ( !strcmp(v6 + 1, "h") || !strcmp(v6 + 1, "D") )
{
syntax();
return 1;
}
if ( !strcmp(v6 + 1, "l") )
{
++i;
v11 = argv[v5 + 1];
continue;
}
if ( strcmp(v6 + 1, "d") )
goto LABEL_64;
++i;
filename = (char *)argv[v5 + 1];
}
}
}
}
if ( v13 != 5 )
{
if ( v13 > 5 )
{
if ( v13 - 7 > 1 )
goto LABEL_82;
while ( 1 )
{
v9 = fread(ptr, 1uLL, 0x1000uLL, stream);
if ( !v9 )
break;
fwrite(ptr, 1uLL, v9, v18[0]);
}
v4 = 0;
LABEL_94:
if ( stream == stdin )
fflush(stream);
else
fclose(stream);
if ( v18[0] == stdout )
fflush(v18[0]);
else
fclose(v18[0]);
if ( v4 < 0 )
remove(filename);
return v4;
}
if ( v13 )
{
LABEL_82:
fprintf(stderr, "unsupported mode %d\n", v13);
v4 = -1;
goto LABEL_94;
}
v7 = v18[0];
if ( v18[0] )
{
v8 = stream;
if ( !stream )
return -1;
goto LABEL_86;
}
LABEL_102:
set_file(1, "messages.mo", v18);
v8 = stream;
if ( !stream )
return -1;
v7 = v18[0];
if ( !v18[0] )
return -1;
LABEL_86:
v4 = process(v8, v7, v14);
goto LABEL_94;
}
if ( v11 && filename )
{
snprintf(s, 0x1000uLL, "%s/%s.msg", filename, v11);
v18[0] = fopen(s, "w");
v4 = 0;
if ( !v18[0] )
{
perror("fopen");
v4 = -1;
}
goto LABEL_94;
}
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // ebx
__int64 v5; // r13
const char *v6; // rbp
FILE *v7; // rsi
FILE *v8; // rdi
size_t v9; // rdx
const char *v11; // [rsp+8h] [rbp-2060h]
char *filename; // [rsp+10h] [rbp-2058h]
unsigned int v13; // [rsp+18h] [rbp-2050h]
char v14; // [rsp+1Fh] [rbp-2049h]
char ptr[4096]; // [rsp+20h] [rbp-2048h] BYREF
char s[4096]; // [rsp+1020h] [rbp-1048h] BYREF
FILE *stream; // [rsp+2020h] [rbp-48h] BYREF
FILE *v18[8]; // [rsp+2028h] [rbp-40h] BYREF

if ( argc == 1 )
{
func3();
return 1;
}
v18[0] = 0LL;
stream = 0LL;
if ( argc <= 1 )
{
filename = 0LL;
v14 = 0;
goto LABEL_102;
}
filename = 0LL;
v11 = 0LL;
v14 = 0;
v13 = 0;
for ( i = 1; i < argc; ++i )
{
v5 = i;
v6 = argv[v5];
if ( *v6 != 45 )
goto LABEL_64;
if ( v6[1] == 45 )
{
if ( strcmp(v6 + 2, "template")
&& strcmp(v6 + 2, "strict")
&& strcmp(v6 + 2, "properties-input")
&& strcmp(v6 + 2, "stringtable-input")
&& strcmp(v6 + 2, "use-fuzzy")
&& memcmp(v6 + 2, "alignment=", 0xAuLL)
&& strcmp(v6 + 2, "check-format")
&& strcmp(v6 + 2, "check-header")
&& strcmp(v6 + 2, "check-domain")
&& strcmp(v6 + 2, "check-compatibility")
&& strcmp(v6 + 2, "check-accelerators")
&& strcmp(v6 + 2, "no-hash")
&& strcmp(v6 + 2, "verbose")
&& strcmp(v6 + 2, "statistics")
&& memcmp(v6 + 2, "keyword=", 8uLL)
&& memcmp(v6 + 2, "check-accelerators=", 0x13uLL)
&& memcmp(v6 + 2, "resource=", 9uLL) )
{
if ( !strcmp(v6 + 2, "java") )
{
v13 = 1;
}
else if ( !strcmp(v6 + 2, "java2") )
{
v13 = 2;
}
else if ( !strcmp(v6 + 2, "csharp") )
{
v13 = 3;
}
else if ( !strcmp(v6 + 2, "csharp-resources") )
{
v13 = 4;
}
else if ( !strcmp(v6 + 2, "tcl") )
{
v13 = 5;
}
else if ( !strcmp(v6 + 2, "qt") )
{
v13 = 6;
}
else if ( !strcmp(v6 + 2, "desktop") )
{
v13 = 7;
}
else if ( !strcmp(v6 + 2, "xml") )
{
v13 = 8;
}
else
{
if ( !strcmp(v6 + 2, "keyword") )
{
++i;
continue;
}
if ( !memcmp(v6 + 2, "locale=", 7uLL) )
{
v11 = v6 + 9;
continue;
}
if ( strcmp(v6 + 2, "check") )
{
if ( !memcmp(v6 + 2, "template=", 9uLL) )
{
func5(0, v6 + 11, &stream);
v11 = 0LL;
continue;
}
if ( !memcmp(v6 + 2, "output-file=", 0xCuLL) )
{
func5(1, v6 + 14, v18);
v11 = 0LL;
continue;
}
if ( !memcmp(v6 + 2, "output=", 7uLL) )
{
func5(1, v6 + 9, v18);
v11 = 0LL;
continue;
}
if ( !strcmp(v6 + 2, "version") )
{
LABEL_59:
v4 = 0;
func2();
return v4;
}
if ( !strcmp(v6 + 2, "help") )
{
v4 = 0;
func3();
return v4;
}
v11 = 0LL;
LABEL_64:
func5(0, v6, &stream);
continue;
}
v11 = 0LL;
v14 = 1;
}
}
}
else
{
if ( !strcmp(v6 + 1, LC40) )
{
++i;
func5(1, argv[v5 + 1], v18);
continue;
}
if ( strcmp(v6 + 1, "j")
&& strcmp(v6 + 1, "r")
&& strcmp(v6 + 1, "P")
&& strcmp(v6 + 1, "f")
&& strcmp(v6 + 1, "a")
&& strcmp(v6 + 1, "v")
&& strcmp(v6 + 1, "C") )
{
if ( !strcmp(v6 + 1, "c") )
{
v14 = 1;
}
else
{
if ( !strcmp(v6 + 1, "V") )
goto LABEL_59;
if ( !strcmp(v6 + 1, "h") || !strcmp(v6 + 1, "D") )
{
func3();
return 1;
}
if ( !strcmp(v6 + 1, "l") )
{
++i;
v11 = argv[v5 + 1];
continue;
}
if ( strcmp(v6 + 1, "d") )
goto LABEL_64;
++i;
filename = (char *)argv[v5 + 1];
}
}
}
}
if ( v13 != 5 )
{
if ( v13 > 5 )
{
if ( v13 - 7 > 1 )
goto LABEL_82;
while ( 1 )
{
v9 = fread(ptr, 1uLL, 0x1000uLL, stream);
if ( !v9 )
break;
fwrite(ptr, 1uLL, v9, v18[0]);
}
v4 = 0;
LABEL_94:
if ( stream == stdin )
fflush(stream);
else
fclose(stream);
if ( v18[0] == stdout )
fflush(v18[0]);
else
fclose(v18[0]);
if ( v4 < 0 )
remove(filename);
return v4;
}
if ( v13 )
{
LABEL_82:
fprintf(stderr, "unsupported mode %d\n", v13);
v4 = -1;
goto LABEL_94;
}
v7 = v18[0];
if ( v18[0] )
{
v8 = stream;
if ( !stream )
return -1;
goto LABEL_86;
}
LABEL_102:
func5(1, "messages.mo", v18);
v8 = stream;
if ( !stream )
return -1;
v7 = v18[0];
if ( !v18[0] )
return -1;
LABEL_86:
v4 = func4(v8, v7, v14);
goto LABEL_94;
}
if ( v11 && filename )
{
snprintf(s, 0x1000uLL, "%s/%s.msg", filename, v11);
v18[0] = fopen(s, "w");
v4 = 0;
if ( !v18[0] )
{
perror("fopen");
v4 = -1;
}
goto LABEL_94;
}
return -1;
}

original_code: int main(){}

canonical_original_code: int main(){}


version

decompiled_code:
size_t version()
{
return fwrite("msgfmt (GNU gettext-tools compatible) 99.9999.9999\n", 1uLL, 0x33uLL, stdout);
}

canonical_decompiled_code:
size_t func2()
{
return fwrite("msgfmt (GNU gettext-tools compatible) 99.9999.9999\n", 1uLL, 0x33uLL, stdout);
}

original_code:
static void version(void) {
 fprintf(stdout, "msgfmt (GNU gettext-tools compatible) 99.9999.9999\n");
}

canonical_original_code:
static void version() {
 fprintf(stdout, "msgfmt (GNU gettext-tools compatible) 99.9999.9999\n");
}


syntax

decompiled_code:
size_t syntax()
{
return fwrite("Usage: msgfmt [OPTION] filename.po ...\n", 1uLL, 0x27uLL, stdout);
}

canonical_decompiled_code:
size_t func3()
{
return fwrite("Usage: msgfmt [OPTION] filename.po ...\n", 1uLL, 0x27uLL, stdout);
}

original_code:
static void syntax(void) {
 fprintf(stdout, "Usage: msgfmt [OPTION] filename.po ...\n");
}

canonical_original_code:
static void syntax() {
 fprintf(stdout, "Usage: msgfmt [OPTION] filename.po ...\n");
}


gettext

decompiled_code:
__int64 __fastcall gettext(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
char *gettext(const char *msgid)
{
 return (char *) msgid;
}

canonical_original_code:
char *gettext(char *msgid)
{
 return (char *) msgid;
}

variable_types:
msgid
char *


dgettext

decompiled_code:
__int64 __fastcall dgettext(__int64 a1, __int64 a2)
{
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return a2;
}

original_code:
char *dgettext(const char *domainname, const char *msgid)
{
 (void) domainname;
 return (char *) msgid;
}

canonical_original_code:
char *dgettext(char *domainname, char *msgid)
{
 (void) domainname;
 return (char *) msgid;
}

variable_types:
domainname
char *


dcgettext

decompiled_code:
__int64 __fastcall dcgettext(__int64 a1, __int64 a2)
{
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return a2;
}

original_code:
char *dcgettext(const char *domainname, const char *msgid, int category)
{
 (void) domainname;
 (void) category;
 return (char *) msgid;
}

canonical_original_code:
char *dcgettext(char *domainname, char *msgid, int category)
{
 (void) domainname;
 (void) category;
 return (char *) msgid;
}

variable_types: category int


ngettext

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

result = a2;
if ( a3 == 1 )
result = a1;
return result;
}

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

result = a2;
if ( a3 == 1 )
result = a1;
return result;
}

original_code:
char *ngettext(const char *msgid1, const char *msgid2, unsigned long n)
{
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

canonical_original_code:
char *ngettext(char *msgid1, char *msgid2, unsigned long n)
{
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

variable_types:
n
unsigned long


dngettext

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

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

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

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

original_code:
char *dngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long n)
{
 (void) domainname;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

canonical_original_code:
char *dngettext(char *domainname, char *msgid1, char *msgid2, unsigned long n)
{
 (void) domainname;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}


dcngettext

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

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

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

result = a3;
if ( a4 == 1 )
result = a2;
return result;
}

original_code:
char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long n, int category)
{
 (void) domainname;
 (void) category;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}

canonical_original_code:
char *dcngettext(char *domainname, char *msgid1, char *msgid2, unsigned long n, int category)
{
 (void) domainname;
 (void) category;
 return (char *) ((n == 1) ? msgid1 : msgid2);
}