DoFBFC

decompiled_code:
__int64 DoFBFC()
{
unsigned int v0; // ebx
unsigned int v1; // ebp
__int64 v2; // rax
unsigned int v3; // ebp
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rdx

if ( (CmdMod & 8) != 0 )
{
SIncrm = 2LL * (MArgmt < NArgmt) - 1;
v0 = GetAra();
if ( v0 == -1 )
return v0;
if ( AraBeg >= GapBeg )
{
if ( SIncrm != 1LL )
{
EBPtr1 = AraEnd;
goto LABEL_32;
}
}
else if ( AraEnd > GapEnd )
{
v1 = AraEnd - GapEnd;
v0 = AraEnd - GapEnd;
GapBeg -= AraEnd - GapEnd;
GapEnd -= AraEnd - GapEnd;
ZCpyBl(GapEnd + 1LL, GapBeg, v1);
if ( SIncrm != 1LL )
{
EBPtr1 = AraEnd;
if ( v1 )
{
v2 = GapEnd + 1LL;
LABEL_10:
EndSAr = v2;
LABEL_11:
RhtSid = EBfEnd;
goto LABEL_12;
}
LABEL_32:
v2 = AraBeg;
v0 = 0;
goto LABEL_10;
}
if ( v1 )
{
v5 = GapEnd + 1LL;
LABEL_19:
EBPtr1 = v5;
EndSAr = AraEnd;
goto LABEL_11;
}
}
else if ( SIncrm != 1LL )
{
EBPtr1 = AraEnd;
goto LABEL_32;
}
v5 = AraBeg;
v0 = 0;
goto LABEL_19;
}
if ( NArgmt <= 0 )
{
SIncrm = -1LL;
v7 = GapBeg;
EBPtr1 = GapBeg - 1LL;
EndSAr = Ln2Chr() + v7;
RhtSid = GapBeg - 1LL;
}
else
{
SIncrm = 1LL;
v6 = GapEnd;
EBPtr1 = GapEnd + 1LL;
EndSAr = Ln2Chr() + v6;
RhtSid = EBfEnd;
}
v0 = 0;
LABEL_12:
if ( (unsigned int)SSerch() == -1 )
return (unsigned int)-1;
v3 = Matchd;
if ( Matchd )
{
if ( EBPtr2 < GapEnd )
{
v8 = GapBeg - 1LL - EBPtr2;
GapBeg -= (int)v8;
GapEnd -= (int)v8;
ZCpyBl(GapEnd + 1LL, GapBeg, v8);
}
else
{
v4 = EBPtr2 - GapEnd;
ZCpyBl(GapBeg, GapEnd + 1LL, (unsigned int)(EBPtr2 - GapEnd));
GapBeg += v4;
GapEnd += v4;
}
v0 = 0;
}
else if ( v0 )
{
ZCpyBl(GapBeg, GapEnd + 1LL, v0);
GapBeg += (int)v0;
GapEnd += (int)v0;
v0 = v3;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
unsigned int v1; // ebp
__int64 v2; // rax
unsigned int v3; // ebp
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rdx

if ( (CmdMod & 8) != 0 )
{
SIncrm = 2LL * (MArgmt < NArgmt) - 1;
v0 = GetAra();
if ( v0 == -1 )
return v0;
if ( AraBeg >= GapBeg )
{
if ( SIncrm != 1LL )
{
EBPtr1 = AraEnd;
goto LABEL_32;
}
}
else if ( AraEnd > GapEnd )
{
v1 = AraEnd - GapEnd;
v0 = AraEnd - GapEnd;
GapBeg -= AraEnd - GapEnd;
GapEnd -= AraEnd - GapEnd;
ZCpyBl(GapEnd + 1LL, GapBeg, v1);
if ( SIncrm != 1LL )
{
EBPtr1 = AraEnd;
if ( v1 )
{
v2 = GapEnd + 1LL;
LABEL_10:
EndSAr = v2;
LABEL_11:
RhtSid = EBfEnd;
goto LABEL_12;
}
LABEL_32:
v2 = AraBeg;
v0 = 0;
goto LABEL_10;
}
if ( v1 )
{
v5 = GapEnd + 1LL;
LABEL_19:
EBPtr1 = v5;
EndSAr = AraEnd;
goto LABEL_11;
}
}
else if ( SIncrm != 1LL )
{
EBPtr1 = AraEnd;
goto LABEL_32;
}
v5 = AraBeg;
v0 = 0;
goto LABEL_19;
}
if ( NArgmt <= 0 )
{
SIncrm = -1LL;
v7 = GapBeg;
EBPtr1 = GapBeg - 1LL;
EndSAr = Ln2Chr() + v7;
RhtSid = GapBeg - 1LL;
}
else
{
SIncrm = 1LL;
v6 = GapEnd;
EBPtr1 = GapEnd + 1LL;
EndSAr = Ln2Chr() + v6;
RhtSid = EBfEnd;
}
v0 = 0;
LABEL_12:
if ( (unsigned int)SSerch() == -1 )
return (unsigned int)-1;
v3 = Matchd;
if ( Matchd )
{
if ( EBPtr2 < GapEnd )
{
v8 = GapBeg - 1LL - EBPtr2;
GapBeg -= (int)v8;
GapEnd -= (int)v8;
ZCpyBl(GapEnd + 1LL, GapBeg, v8);
}
else
{
v4 = EBPtr2 - GapEnd;
ZCpyBl(GapBeg, GapEnd + 1LL, (unsigned int)(EBPtr2 - GapEnd));
GapBeg += v4;
GapEnd += v4;
}
v0 = 0;
}
else if ( v0 )
{
ZCpyBl(GapBeg, GapEnd + 1LL, v0);
GapBeg += (int)v0;
GapEnd += (int)v0;
v0 = v3;
}
return v0;
}

original_code:
static DEFAULT DoFBFC()
{
    int HowFar;
    int Shuffl;
    Shuffl = 0;
    if (CmdMod & '\10') {
 SIncrm = (MArgmt < NArgmt) ? 1 : -1;
 if (GetAra() == (-1)) {
     ;
     return (-1);
 }
 if ((AraBeg < GapBeg) && (AraEnd > GapEnd)) {
     Shuffl = AraEnd - GapEnd;
     GapBeg -= Shuffl;
     GapEnd -= Shuffl;
     ZCpyBl((GapEnd+1),(GapBeg),((SIZE_T)Shuffl));
 }
 if (SIncrm == 1) {
     EBPtr1 = (Shuffl!=0 ? GapEnd + 1 : AraBeg);
     EndSAr = AraEnd;
 } else {
     EBPtr1 = AraEnd;
     EndSAr = (Shuffl!=0 ? GapEnd + 1 : AraBeg);
 }
 RhtSid = EBfEnd;
    } else {
 if (NArgmt > 0) {
     SIncrm = 1;
     EBPtr1 = GapEnd + 1;
     EndSAr = GapEnd + Ln2Chr(NArgmt);
     RhtSid = EBfEnd;
 } else {
     SIncrm = -1;
     EBPtr1 = GapBeg - 1;
     EndSAr = GapBeg + Ln2Chr(NArgmt);
     RhtSid = GapBeg - 1;
 }
    }
    if (SSerch() == (-1)) {
 ;
 return (-1);
    }
    if (Matchd) {
 if (EBPtr2 >= GapEnd) {
     HowFar = EBPtr2 - GapEnd;
     ZCpyBl((GapBeg),(GapEnd+1),((SIZE_T)HowFar));
     GapBeg += HowFar;
     GapEnd += HowFar;
 } else {
     HowFar = (GapBeg-1) - EBPtr2;
     GapBeg -= HowFar;
     GapEnd -= HowFar;
     ZCpyBl((GapEnd+1),(GapBeg),((SIZE_T)HowFar));
 }
    } else {
 if (Shuffl != 0) {
     ZCpyBl((GapBeg),(GapEnd+1),((SIZE_T)Shuffl));
     GapBeg += Shuffl;
     GapEnd += Shuffl;
 }
    }
    return 0;
}

canonical_original_code:
static int DoFBFC()
{
    int HowFar;
    int Shuffl;
    Shuffl = 0;
    if (CmdMod & '\10') {
 SIncrm = (MArgmt < NArgmt) ? 1 : -1;
 if (GetAra() == (-1)) {
     ;
     return (-1);
 }
 if ((AraBeg < GapBeg) && (AraEnd > GapEnd)) {
     Shuffl = AraEnd - GapEnd;
     GapBeg -= Shuffl;
     GapEnd -= Shuffl;
     ZCpyBl((GapEnd+1),(GapBeg),((unsigned int)Shuffl));
 }
 if (SIncrm == 1) {
     EBPtr1 = (Shuffl!=0 ? GapEnd + 1 : AraBeg);
     EndSAr = AraEnd;
 } else {
     EBPtr1 = AraEnd;
     EndSAr = (Shuffl!=0 ? GapEnd + 1 : AraBeg);
 }
 RhtSid = EBfEnd;
    } else {
 if (NArgmt > 0) {
     SIncrm = 1;
     EBPtr1 = GapEnd + 1;
     EndSAr = GapEnd + Ln2Chr(NArgmt);
     RhtSid = EBfEnd;
 } else {
     SIncrm = -1;
     EBPtr1 = GapBeg - 1;
     EndSAr = GapBeg + Ln2Chr(NArgmt);
     RhtSid = GapBeg - 1;
 }
    }
    if (SSerch() == (-1)) {
 ;
 return (-1);
    }
    if (Matchd) {
 if (EBPtr2 >= GapEnd) {
     HowFar = EBPtr2 - GapEnd;
     ZCpyBl((GapBeg),(GapEnd+1),((unsigned int)HowFar));
     GapBeg += HowFar;
     GapEnd += HowFar;
 } else {
     HowFar = (GapBeg-1) - EBPtr2;
     GapBeg -= HowFar;
     GapEnd -= HowFar;
     ZCpyBl((GapEnd+1),(GapBeg),((unsigned int)HowFar));
 }
    } else {
 if (Shuffl != 0) {
     ZCpyBl((GapBeg),(GapEnd+1),((unsigned int)Shuffl));
     GapBeg += Shuffl;
     GapEnd += Shuffl;
 }
    }
    return 0;
}

variable_types: HowFar int

variable_types: Shuffl int


SrcLop

repo: rmblair/tecoc

decompiled_code:
__int64 SrcLop()
{
__int64 result; // rax
int v1; // ebx
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rcx

if ( SrcTyp == 2 )
return DoFBFC();
if ( NArgmt > 0 )
{
SIncrm = 1LL;
EBPtr1 = GapEnd;
RhtSid = EBfEnd;
EndSAr = EBfEnd;
while ( 1 )
{
++EBPtr1;
result = SSerch();
if ( (_DWORD)result == -1 )
return result;
if ( Matchd )
{
--NArgmt;
if ( (EdFlag & 0x40) == 0 )
EBPtr1 = EBPtr2;
}
else
{
switch ( SrcTyp )
{
case 1:
goto LABEL_18;
case 3:
case 5:
NArgmt = 0LL;
goto LABEL_20;
case 4:
if ( *((_DWORD *)&IsEofI + CurInp) )
{
result = WrPage(CurOut, EBfBeg, EBfEnd, FFPage);
if ( (_DWORD)result == -1 )
return result;
GapBeg = EBfBeg;
GapEnd = EBfEnd;
NArgmt = 0LL;
LABEL_10:
if ( !Matchd )
{
LABEL_20:
result = 0LL;
if ( (EdFlag & 0x10) == 0 )
{
v3 = GapBeg - EBfBeg;
v4 = GapBeg - EBfBeg;
GapBeg -= v4;
GapEnd -= v4;
ZCpyBl(GapEnd + 1LL, GapBeg, v3);
result = 0LL;
}
return result;
}
LABEL_34:
if ( SrcTyp == 3 )
{
if ( SIncrm == 1LL )
{
GapEnd = EBPtr2;
result = 0LL;
}
else
{
GapBeg = EBPtr1;
result = 0LL;
if ( EBPtr2 > GapEnd )
GapEnd = EBPtr2;
}
}
else if ( SIncrm == 1LL || EBPtr2 > GapEnd )
{
v1 = EBPtr2 - GapEnd;
ZCpyBl(GapBeg, GapEnd + 1LL, (unsigned int)(EBPtr2 - GapEnd));
GapBeg += v1;
GapEnd += v1;
result = 0LL;
}
else
{
v2 = GapBeg - 1LL - EBPtr2;
GapBeg -= (int)v2;
GapEnd -= (int)v2;
ZCpyBl(GapEnd + 1LL, GapBeg, v2);
result = 0LL;
}
return result;
}
result = SinglP();
if ( (_DWORD)result == -1 )
return result;
EBPtr1 = GapEnd + 1LL;
RhtSid = EBfEnd;
EndSAr = EBfEnd;
break;
case 6:
if ( (EdFlag & 2) == 0 && *((_DWORD *)&IsOpnO + CurOut) && (GapBeg != EBfBeg || GapEnd != EBfEnd) )
{
ErrMsg(42LL);
return 0xFFFFFFFFLL;
}
LABEL_18:
GapBeg = EBfBeg;
GapEnd = EBfEnd;
if ( *((_DWORD *)&IsEofI + CurInp) )
{
NArgmt = 0LL;
goto LABEL_20;
}
result = RdPage();
if ( (_DWORD)result == -1 )
return result;
EBPtr1 = GapEnd + 1LL;
RhtSid = EBfEnd;
EndSAr = EBfEnd;
break;
default:
break;
}
}
if ( NArgmt <= 0 )
goto LABEL_10;
}
}
SIncrm = -1LL;
EBPtr1 = GapBeg;
RhtSid = GapBeg - 1LL;
EndSAr = EBfBeg;
while ( 1 )
{
--EBPtr1;
result = SSerch();
if ( (_DWORD)result == -1 )
return result;
if ( !Matchd )
break;
++NArgmt;
if ( NArgmt >= 0 )
goto LABEL_34;
}
if ( ((SrcTyp - 3) & 0xFFFD) == 0 )
goto LABEL_20;
return ExeNYI();
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // ebx
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rcx

if ( SrcTyp == 2 )
return func0();
if ( NArgmt > 0 )
{
SIncrm = 1LL;
EBPtr1 = GapEnd;
RhtSid = EBfEnd;
EndSAr = EBfEnd;
while ( 1 )
{
++EBPtr1;
result = SSerch();
if ( (_DWORD)result == -1 )
return result;
if ( Matchd )
{
--NArgmt;
if ( (EdFlag & 0x40) == 0 )
EBPtr1 = EBPtr2;
}
else
{
switch ( SrcTyp )
{
case 1:
goto LABEL_18;
case 3:
case 5:
NArgmt = 0LL;
goto LABEL_20;
case 4:
if ( *((_DWORD *)&IsEofI + CurInp) )
{
result = WrPage(CurOut, EBfBeg, EBfEnd, FFPage);
if ( (_DWORD)result == -1 )
return result;
GapBeg = EBfBeg;
GapEnd = EBfEnd;
NArgmt = 0LL;
LABEL_10:
if ( !Matchd )
{
LABEL_20:
result = 0LL;
if ( (EdFlag & 0x10) == 0 )
{
v3 = GapBeg - EBfBeg;
v4 = GapBeg - EBfBeg;
GapBeg -= v4;
GapEnd -= v4;
ZCpyBl(GapEnd + 1LL, GapBeg, v3);
result = 0LL;
}
return result;
}
LABEL_34:
if ( SrcTyp == 3 )
{
if ( SIncrm == 1LL )
{
GapEnd = EBPtr2;
result = 0LL;
}
else
{
GapBeg = EBPtr1;
result = 0LL;
if ( EBPtr2 > GapEnd )
GapEnd = EBPtr2;
}
}
else if ( SIncrm == 1LL || EBPtr2 > GapEnd )
{
v1 = EBPtr2 - GapEnd;
ZCpyBl(GapBeg, GapEnd + 1LL, (unsigned int)(EBPtr2 - GapEnd));
GapBeg += v1;
GapEnd += v1;
result = 0LL;
}
else
{
v2 = GapBeg - 1LL - EBPtr2;
GapBeg -= (int)v2;
GapEnd -= (int)v2;
ZCpyBl(GapEnd + 1LL, GapBeg, v2);
result = 0LL;
}
return result;
}
result = SinglP();
if ( (_DWORD)result == -1 )
return result;
EBPtr1 = GapEnd + 1LL;
RhtSid = EBfEnd;
EndSAr = EBfEnd;
break;
case 6:
if ( (EdFlag & 2) == 0 && *((_DWORD *)&IsOpnO + CurOut) && (GapBeg != EBfBeg || GapEnd != EBfEnd) )
{
ErrMsg(42LL);
return 0xFFFFFFFFLL;
}
LABEL_18:
GapBeg = EBfBeg;
GapEnd = EBfEnd;
if ( *((_DWORD *)&IsEofI + CurInp) )
{
NArgmt = 0LL;
goto LABEL_20;
}
result = RdPage();
if ( (_DWORD)result == -1 )
return result;
EBPtr1 = GapEnd + 1LL;
RhtSid = EBfEnd;
EndSAr = EBfEnd;
break;
default:
break;
}
}
if ( NArgmt <= 0 )
goto LABEL_10;
}
}
SIncrm = -1LL;
EBPtr1 = GapBeg;
RhtSid = GapBeg - 1LL;
EndSAr = EBfBeg;
while ( 1 )
{
--EBPtr1;
result = SSerch();
if ( (_DWORD)result == -1 )
return result;
if ( !Matchd )
break;
++NArgmt;
if ( NArgmt >= 0 )
goto LABEL_34;
}
if ( ((SrcTyp - 3) & 0xFFFD) == 0 )
goto LABEL_20;
return ExeNYI();
}

original_code:
DEFAULT SrcLop()
{
    int HowFar;
    if (SrcTyp == 2) {
 ;
 return DoFBFC();
    }
    if (NArgmt > 0) {
 SIncrm = 1;
 EBPtr1 = GapEnd;
 EndSAr = RhtSid = EBfEnd;
 do {
     EBPtr1++;
     if (SSerch() == (-1)) {
  ;
  return (-1);
     }
     if (Matchd) {
  --NArgmt;
  if ((EdFlag & 64) == 0)
      EBPtr1 = EBPtr2;
     } else {
  switch (SrcTyp) {
      case 5:
      case 3:
   NArgmt = 0;
   break;
      case 4:
   if (IsEofI[CurInp]) {
       if (WrPage(CurOut,EBfBeg,
     EBfEnd,FFPage) == (-1)) {
    ;
    return (-1);
       }
       GapBeg = EBfBeg;
       GapEnd = EBfEnd;
       NArgmt = 0;
   } else {
       if (SinglP() == (-1)) {
    ;
    return (-1);
       }
       EBPtr1 = GapEnd + 1;
       EndSAr = RhtSid = EBfEnd;
   }
   break;
      case 6:
   if (((EdFlag & 2) == 0) &&
       (IsOpnO[CurOut]) &&
       ((GapBeg != EBfBeg) || (GapEnd != EBfEnd))) {
    ErrMsg(42);
    ;
    return (-1);
   }
      case 1:
   GapBeg = EBfBeg;
   GapEnd = EBfEnd;
   if (IsEofI[CurInp]) {
       NArgmt = 0;
   } else {
      if (RdPage() == (-1)) {
    ;
    return (-1);
       }
       EBPtr1 = GapEnd + 1;
       EndSAr = RhtSid = EBfEnd;
   }
  }
     }
 } while (NArgmt > 0);
    } else {
 SIncrm = -1;
 EBPtr1 = RhtSid = GapBeg;
 RhtSid--;
 EndSAr = EBfBeg;
 do {
     EBPtr1--;
     if (SSerch() == (-1)) {
  ;
  return (-1);
     }
     if (Matchd) {
  ++NArgmt;
     } else {
  if ((SrcTyp==5) || (SrcTyp==3)) {
      break;
  } else {
      ;
      return ExeNYI();
  }
     }
 } while (NArgmt < 0);
    }
    if (Matchd) {
 if (SrcTyp == 3) {
     if (SIncrm == 1) {
  GapEnd = EBPtr2;
     } else {
  GapBeg = EBPtr1;
  if (EBPtr2 > GapEnd)
      GapEnd = EBPtr2;
     }
 } else {
     if ((SIncrm == 1) || (EBPtr2 > GapEnd)) {
  HowFar = EBPtr2 - GapEnd;
  ZCpyBl((GapBeg),(GapEnd+1),((SIZE_T)HowFar));
  GapBeg += HowFar;
  GapEnd += HowFar;
     } else {
  HowFar = (GapBeg-1) - EBPtr2;
  GapBeg -= HowFar;
  GapEnd -= HowFar;
  ZCpyBl((GapEnd+1),(GapBeg),((SIZE_T)HowFar));
     }
 }
    } else {
 if ((EdFlag & 16) == 0) {
     HowFar = GapBeg - EBfBeg;
     GapBeg -= HowFar;
     GapEnd -= HowFar;
     ZCpyBl((GapEnd+1),(GapBeg),((SIZE_T)HowFar));
 }
    }
    return 0;
}

canonical_original_code:
int SrcLop()
{
    int HowFar;
    if (SrcTyp == 2) {
 ;
 return DoFBFC();
    }
    if (NArgmt > 0) {
 SIncrm = 1;
 EBPtr1 = GapEnd;
 EndSAr = RhtSid = EBfEnd;
 do {
     EBPtr1++;
     if (SSerch() == (-1)) {
  ;
  return (-1);
     }
     if (Matchd) {
  --NArgmt;
  if ((EdFlag & 64) == 0)
      EBPtr1 = EBPtr2;
     } else {
  switch (SrcTyp) {
      case 5:
      case 3:
   NArgmt = 0;
   break;
      case 4:
   if (IsEofI[CurInp]) {
       if (WrPage(CurOut,EBfBeg,
     EBfEnd,FFPage) == (-1)) {
    ;
    return (-1);
       }
       GapBeg = EBfBeg;
       GapEnd = EBfEnd;
       NArgmt = 0;
   } else {
       if (SinglP() == (-1)) {
    ;
    return (-1);
       }
       EBPtr1 = GapEnd + 1;
       EndSAr = RhtSid = EBfEnd;
   }
   break;
      case 6:
   if (((EdFlag & 2) == 0) &&
       (IsOpnO[CurOut]) &&
       ((GapBeg != EBfBeg) || (GapEnd != EBfEnd))) {
    ErrMsg(42);
    ;
    return (-1);
   }
      case 1:
   GapBeg = EBfBeg;
   GapEnd = EBfEnd;
   if (IsEofI[CurInp]) {
       NArgmt = 0;
   } else {
      if (RdPage() == (-1)) {
    ;
    return (-1);
       }
       EBPtr1 = GapEnd + 1;
       EndSAr = RhtSid = EBfEnd;
   }
  }
     }
 } while (NArgmt > 0);
    } else {
 SIncrm = -1;
 EBPtr1 = RhtSid = GapBeg;
 RhtSid--;
 EndSAr = EBfBeg;
 do {
     EBPtr1--;
     if (SSerch() == (-1)) {
  ;
  return (-1);
     }
     if (Matchd) {
  ++NArgmt;
     } else {
  if ((SrcTyp==5) || (SrcTyp==3)) {
      break;
  } else {
      ;
      return ExeNYI();
  }
     }
 } while (NArgmt < 0);
    }
    if (Matchd) {
 if (SrcTyp == 3) {
     if (SIncrm == 1) {
  GapEnd = EBPtr2;
     } else {
  GapBeg = EBPtr1;
  if (EBPtr2 > GapEnd)
      GapEnd = EBPtr2;
     }
 } else {
     if ((SIncrm == 1) || (EBPtr2 > GapEnd)) {
  HowFar = EBPtr2 - GapEnd;
  ZCpyBl((GapBeg),(GapEnd+1),((unsigned int)HowFar));
  GapBeg += HowFar;
  GapEnd += HowFar;
     } else {
  HowFar = (GapBeg-1) - EBPtr2;
  GapBeg -= HowFar;
  GapEnd -= HowFar;
  ZCpyBl((GapEnd+1),(GapBeg),((unsigned int)HowFar));
     }
 }
    } else {
 if ((EdFlag & 16) == 0) {
     HowFar = GapBeg - EBfBeg;
     GapBeg -= HowFar;
     GapEnd -= HowFar;
     ZCpyBl((GapEnd+1),(GapBeg),((unsigned int)HowFar));
 }
    }
    return 0;
}

return_type: int


ExeLst

decompiled_code:
__int64 ExeLst()
{
__int64 v0; // rax
__int64 result; // rax

++LStTop;
if ( LStTop > 31 )
{
ErrMsg(32LL);
return 0xFFFFFFFFLL;
}
if ( EStTop == EStBot )
{
NArgmt = -1LL;
LABEL_4:
v0 = 16LL * LStTop;
*(_QWORD *)((char *)&LStack + v0) = NArgmt;
*(_QWORD *)((char *)&LStack + v0 + 8) = CBfPtr;
CmdMod = 0;
return 0LL;
}
result = GetNmA();
if ( (_DWORD)result != -1 )
{
if ( NArgmt > 0 )
goto LABEL_4;
result = FlowEL();
if ( (_DWORD)result != -1 )
{
CmdMod = 0;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 result; // rax

++LStTop;
if ( LStTop > 31 )
{
ErrMsg(32LL);
return 0xFFFFFFFFLL;
}
if ( EStTop == EStBot )
{
NArgmt = -1LL;
LABEL_4:
v0 = 16LL * LStTop;
*(_QWORD *)((char *)&LStack + v0) = NArgmt;
*(_QWORD *)((char *)&LStack + v0 + 8) = CBfPtr;
CmdMod = 0;
return 0LL;
}
result = GetNmA();
if ( (_DWORD)result != -1 )
{
if ( NArgmt > 0 )
goto LABEL_4;
result = FlowEL();
if ( (_DWORD)result != -1 )
{
CmdMod = 0;
result = 0LL;
}
}
return result;
}

original_code:
DEFAULT ExeLst()
{
 ;
 if (++LStTop >= 32) {
  ErrMsg(32);
  ;
  return (-1);
 }
 if (EStTop == EStBot) {
  NArgmt = -1L;
 } else {
  if (GetNmA() == (-1)) {
   ;
   return (-1);
  }
  if (NArgmt <= 0) {
   if (FlowEL()== (-1)) {
    ;
    return (-1);
   }
   CmdMod = '\0';
   ;
   return 0;
  }
 }
 LStack[LStTop].LIndex = NArgmt;
 LStack[LStTop].LAddr = CBfPtr;
 CmdMod = '\0';
 ;
 return 0;
}

canonical_original_code:
int ExeLst()
{
 ;
 if (++LStTop >= 32) {
  ErrMsg(32);
  ;
  return (-1);
 }
 if (EStTop == EStBot) {
  NArgmt = -1L;
 } else {
  if (GetNmA() == (-1)) {
   ;
   return (-1);
  }
  if (NArgmt <= 0) {
   if (FlowEL()== (-1)) {
    ;
    return (-1);
   }
   CmdMod = '\0';
   ;
   return 0;
  }
 }
 LStack[LStTop].LIndex = NArgmt;
 LStack[LStTop].LAddr = CBfPtr;
 CmdMod = '\0';
 ;
 return 0;
}


SSerch

decompiled_code:
__int64 SSerch()
{
__int64 result; // rax
unsigned __int64 v1; // rax
unsigned int v2[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( SBfPtr == SBfBeg )
{
Matchd = 0;
result = 0LL;
}
else
{
while ( 2 )
{
SStPtr = SBfBeg;
if ( SIncrm == 1LL )
{
result = ZFrSrc();
if ( (_DWORD)result != -1 )
{
if ( EBPtr1 <= EndSAr )
{
do
{
LABEL_18:
if ( ++SStPtr == SBfPtr )
{
RefLen = EBPtr1 + ~EBPtr2;
if ( SIncrm == -1LL && EBPtr2 >= GapEnd )
RefLen = EBPtr1 + ~EBPtr2 + GapEnd - GapBeg + 1LL;
Matchd = 1;
return 0LL;
}
v1 = EBPtr2 + 1LL;
EBPtr2 = v1;
if ( v1 > RhtSid )
{
if ( SIncrm != -1LL )
{
Matchd = 0;
return 0LL;
}
if ( v1 < GapEnd )
EBPtr2 = GapEnd + 1LL;
}
result = CMatch(v2);
if ( (_DWORD)result == -1 )
return result;
result = v2[0];
}
while ( v2[0] );
if ( SIncrm == 1LL )
{
if ( ++EBPtr1 <= EndSAr )
continue;
Matchd = 0;
}
else
{
if ( --EBPtr1 >= EndSAr )
continue;
Matchd = 0;
}
}
else
{
Matchd = 0;
result = 0LL;
}
}
}
else
{
result = BakSrc();
if ( (_DWORD)result != -1 )
{
if ( EBPtr1 >= EndSAr )
goto LABEL_18;
Matchd = 0;
result = 0LL;
}
}
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
unsigned __int64 v1; // rax
unsigned int v2[3]; // [rsp+0h] [rbp-Ch] BYREF

if ( SBfPtr == SBfBeg )
{
Matchd = 0;
result = 0LL;
}
else
{
while ( 2 )
{
SStPtr = SBfBeg;
if ( SIncrm == 1LL )
{
result = ZFrSrc();
if ( (_DWORD)result != -1 )
{
if ( EBPtr1 <= EndSAr )
{
do
{
LABEL_18:
if ( ++SStPtr == SBfPtr )
{
RefLen = EBPtr1 + ~EBPtr2;
if ( SIncrm == -1LL && EBPtr2 >= GapEnd )
RefLen = EBPtr1 + ~EBPtr2 + GapEnd - GapBeg + 1LL;
Matchd = 1;
return 0LL;
}
v1 = EBPtr2 + 1LL;
EBPtr2 = v1;
if ( v1 > RhtSid )
{
if ( SIncrm != -1LL )
{
Matchd = 0;
return 0LL;
}
if ( v1 < GapEnd )
EBPtr2 = GapEnd + 1LL;
}
result = CMatch(v2);
if ( (_DWORD)result == -1 )
return result;
result = v2[0];
}
while ( v2[0] );
if ( SIncrm == 1LL )
{
if ( ++EBPtr1 <= EndSAr )
continue;
Matchd = 0;
}
else
{
if ( --EBPtr1 >= EndSAr )
continue;
Matchd = 0;
}
}
else
{
Matchd = 0;
result = 0LL;
}
}
}
else
{
result = BakSrc();
if ( (_DWORD)result != -1 )
{
if ( EBPtr1 >= EndSAr )
goto LABEL_18;
Matchd = 0;
result = 0LL;
}
}
break;
}
}
return result;
}

original_code:
DEFAULT SSerch()
{
 BOOLEAN SamChr;
 if (SBfPtr == SBfBeg) {
  Matchd = 0;
  ;
  return 0;
 }
 for(;;) {
  SStPtr = SBfBeg;
  if (SIncrm == 1) {
   if (ZFrSrc() == (-1)) {
    ;
    return (-1);
   }
   if (EBPtr1 > EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  } else {
   if (BakSrc() == (-1)) {
    ;
    return (-1);
   }
   if (EBPtr1 < EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  }
  do {
   if (++SStPtr == SBfPtr) {
    RefLen = (EBPtr1 - EBPtr2) - 1;
    if ((SIncrm == -1) && (EBPtr2 >= GapEnd)) {
     RefLen += GapEnd-GapBeg+1;
    }
    Matchd = 1;
    ;
    return 0;
   }
   if (++EBPtr2 > RhtSid) {
       if (SIncrm == -1) {
    if (EBPtr2 < GapEnd) EBPtr2 = GapEnd+1;
       } else {
    Matchd = 0;
    ;
    return 0;
       }
   }
   if (CMatch(&SamChr) == (-1)) {
    ;
    return (-1);
   }
  } while (SamChr);
  if (SIncrm == 1) {
   if (++EBPtr1 > EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  } else {
   if (--EBPtr1 < EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  }
 }
}

canonical_original_code:
int SSerch()
{
 int SamChr;
 if (SBfPtr == SBfBeg) {
  Matchd = 0;
  ;
  return 0;
 }
 for(;;) {
  SStPtr = SBfBeg;
  if (SIncrm == 1) {
   if (ZFrSrc() == (-1)) {
    ;
    return (-1);
   }
   if (EBPtr1 > EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  } else {
   if (BakSrc() == (-1)) {
    ;
    return (-1);
   }
   if (EBPtr1 < EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  }
  do {
   if (++SStPtr == SBfPtr) {
    RefLen = (EBPtr1 - EBPtr2) - 1;
    if ((SIncrm == -1) && (EBPtr2 >= GapEnd)) {
     RefLen += GapEnd-GapBeg+1;
    }
    Matchd = 1;
    ;
    return 0;
   }
   if (++EBPtr2 > RhtSid) {
       if (SIncrm == -1) {
    if (EBPtr2 < GapEnd) EBPtr2 = GapEnd+1;
       } else {
    Matchd = 0;
    ;
    return 0;
       }
   }
   if (CMatch(&SamChr) == (-1)) {
    ;
    return (-1);
   }
  } while (SamChr);
  if (SIncrm == 1) {
   if (++EBPtr1 > EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  } else {
   if (--EBPtr1 < EndSAr) {
    Matchd = 0;
    ;
    return 0;
   }
  }
 }
}

variable_types: SamChr int


ExeY

decompiled_code:
__int64 ExeY()
{
__int64 result; // rax

if ( EStTop > EStBot )
{
ErrMsg(29LL);
result = 0xFFFFFFFFLL;
}
else if ( (EdFlag & 2) != 0 || !*((_DWORD *)&IsOpnO + CurOut) || GapBeg == EBfBeg && GapEnd == EBfEnd )
{
result = ExeEY();
}
else
{
ErrMsg(42LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

if ( EStTop > EStBot )
{
ErrMsg(29LL);
result = 0xFFFFFFFFLL;
}
else if ( (EdFlag & 2) != 0 || !*((_DWORD *)&IsOpnO + CurOut) || GapBeg == EBfBeg && GapEnd == EBfEnd )
{
result = ExeEY();
}
else
{
ErrMsg(42LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
DEFAULT ExeY()
{
 ;
 if (EStTop > EStBot) {
  ErrMsg(29);
  ;
  return (-1);
 }
 if ((EdFlag & 2) == 0) {
  if (IsOpnO[CurOut] &&
      ((GapBeg != EBfBeg) || (GapEnd != EBfEnd))) {
   ErrMsg(42);
   ;
   return (-1);
  }
 }
 ;
 return ExeEY();
}

canonical_original_code:
int ExeY()
{
 ;
 if (EStTop > EStBot) {
  ErrMsg(29);
  ;
  return (-1);
 }
 if ((EdFlag & 2) == 0) {
  if (IsOpnO[CurOut] &&
      ((GapBeg != EBfBeg) || (GapEnd != EBfEnd))) {
   ErrMsg(42);
   ;
   return (-1);
  }
 }
 ;
 return ExeEY();
}


ExeH

decompiled_code:
__int64 ExeH()
{
MArgmt = 0LL;
CmdMod |= 8u;
return ExeZ();
}

canonical_decompiled_code:
__int64 func0()
{
MArgmt = 0LL;
CmdMod |= 8u;
return ExeZ();
}

original_code:
DEFAULT ExeH()
{
 ;
 MArgmt = 0;
 CmdMod |= '\10';
 ;
 return ExeZ();
}

canonical_original_code:
int ExeH()
{
 ;
 MArgmt = 0;
 CmdMod |= '\10';
 ;
 return ExeZ();
}


ExeG

decompiled_code:
__int64 ExeG()
{
__int64 result; // rax
__int64 v1; // rdi
__int64 v2; // rsi

result = IncCBP();
if ( (_DWORD)result != -1 )
{
v1 = FBfBeg;
v2 = FBfPtr;
if ( *CBfPtr != 42 )
{
if ( *CBfPtr == 95 )
{
v1 = SBfBeg;
v2 = SBfPtr;
}
else
{
result = FindQR(FBfBeg, FBfPtr);
if ( (_DWORD)result == -1 )
return result;
v1 = *QR;
if ( !*QR )
{
RefLen = 0LL;
CmdMod = 0;
EStTop = EStBot;
return 0LL;
}
v2 = *(_QWORD *)(QR + 8LL);
}
}
if ( (CmdMod & 2) != 0 )
{
TypBuf(v1, v2);
}
else
{
result = InsStr(v1, v2 - v1);
if ( (_DWORD)result == -1 )
return result;
}
CmdMod = 0;
EStTop = EStBot;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rdi
__int64 v2; // rsi

result = IncCBP();
if ( (_DWORD)result != -1 )
{
v1 = FBfBeg;
v2 = FBfPtr;
if ( *CBfPtr != 42 )
{
if ( *CBfPtr == 95 )
{
v1 = SBfBeg;
v2 = SBfPtr;
}
else
{
result = FindQR(FBfBeg, FBfPtr);
if ( (_DWORD)result == -1 )
return result;
v1 = *QR;
if ( !*QR )
{
RefLen = 0LL;
CmdMod = 0;
EStTop = EStBot;
return 0LL;
}
v2 = *(_QWORD *)(QR + 8LL);
}
}
if ( (CmdMod & 2) != 0 )
{
TypBuf(v1, v2);
}
else
{
result = InsStr(v1, v2 - v1);
if ( (_DWORD)result == -1 )
return result;
}
CmdMod = 0;
EStTop = EStBot;
result = 0LL;
}
return result;
}

original_code:
DEFAULT ExeG()
{
 charptr TxtBeg;
 charptr TxtEnd;
 ;
 if (IncCBP() == (-1)) {
  ;
  return (-1);
 }
 if (*CBfPtr == '*') {
  TxtBeg = FBfBeg;
  TxtEnd = FBfPtr;
 } else if (*CBfPtr == '_') {
  TxtBeg = SBfBeg;
  TxtEnd = SBfPtr;
 } else {
  if (FindQR() == (-1)) {
   return (-1);
  }
  if (QR->Start == (void *)0) {
   RefLen = 0;
   CmdMod = '\0';
   EStTop = EStBot;
   ;
   return 0;
  }
  TxtBeg = QR->Start;
  TxtEnd = QR->End_P1;
 }
 if (CmdMod & '\2') {
  TypBuf(TxtBeg, TxtEnd);
 } else {
  if (InsStr(TxtBeg, TxtEnd-TxtBeg) == (-1)) {
   ;
   return (-1);
  }
 }
 CmdMod = '\0';
 EStTop = EStBot;
 ;
 return 0;
}

canonical_original_code:
int ExeG()
{
 unsigned char *TxtBeg;
 unsigned char *TxtEnd;
 ;
 if (IncCBP() == (-1)) {
  ;
  return (-1);
 }
 if (*CBfPtr == '*') {
  TxtBeg = FBfBeg;
  TxtEnd = FBfPtr;
 } else if (*CBfPtr == '_') {
  TxtBeg = SBfBeg;
  TxtEnd = SBfPtr;
 } else {
  if (FindQR() == (-1)) {
   return (-1);
  }
  if (QR->Start == (void *)0) {
   RefLen = 0;
   CmdMod = '\0';
   EStTop = EStBot;
   ;
   return 0;
  }
  TxtBeg = QR->Start;
  TxtEnd = QR->End_P1;
 }
 if (CmdMod & '\2') {
  TypBuf(TxtBeg, TxtEnd);
 } else {
  if (InsStr(TxtBeg, TxtEnd-TxtBeg) == (-1)) {
   ;
   return (-1);
  }
 }
 CmdMod = '\0';
 EStTop = EStBot;
 ;
 return 0;
}

variable_types:
TxtBeg
unsigned char *

variable_types:
TxtEnd
unsigned char *


ExeExc

decompiled_code:
__int64 ExeExc()
{
__int64 result; // rax

result = FindES(33LL);
if ( (_DWORD)result != -1 )
{
CmdMod = 0;
EStTop = EStBot;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

result = FindES(33LL);
if ( (_DWORD)result != -1 )
{
CmdMod = 0;
EStTop = EStBot;
result = 0LL;
}
return result;
}

original_code:
DEFAULT ExeExc()
{
 ;
 if (FindES('!') == (-1)) {
  ;
  return (-1);
 }
 CmdMod = '\0';
 EStTop = EStBot;
 ;
 return 0;
}

canonical_original_code:
int ExeExc()
{
 ;
 if (FindES('!') == (-1)) {
  ;
  return (-1);
 }
 CmdMod = '\0';
 EStTop = EStBot;
 ;
 return 0;
}


ExeI

decompiled_code:
__int64 ExeI()
{
__int64 result; // rax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( EStTop <= EStBot )
{
result = FindES(27LL);
if ( (_DWORD)result != -1 )
{
result = InsStr(ArgPtr, CBfPtr - ArgPtr);
if ( (_DWORD)result != -1 )
goto LABEL_18;
}
}
else
{
result = GetNmA();
if ( (_DWORD)result == -1 )
return result;
if ( (CmdMod & 1) != 0 )
{
result = IncCBP();
if ( (_DWORD)result != -1 )
{
result = IncCBP();
if ( (_DWORD)result != -1 )
{
if ( *CBfPtr == *(_BYTE *)(CBfPtr - 1LL) )
{
LABEL_6:
v1[0] = NArgmt;
result = InsStr(v1, 1LL);
if ( (_DWORD)result == -1 )
return result;
LABEL_18:
CmdMod = 0;
return 0LL;
}
LABEL_11:
ErrMsg(7LL);
return 0xFFFFFFFFLL;
}
}
}
else
{
if ( CStEnd != CBfPtr + 1LL )
{
if ( *(_BYTE *)(CBfPtr + 1LL) == 27 )
goto LABEL_6;
goto LABEL_11;
}
if ( MStTop < 0 )
{
ErrUTC();
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( EStTop <= EStBot )
{
result = FindES(27LL);
if ( (_DWORD)result != -1 )
{
result = InsStr(ArgPtr, CBfPtr - ArgPtr);
if ( (_DWORD)result != -1 )
goto LABEL_18;
}
}
else
{
result = GetNmA();
if ( (_DWORD)result == -1 )
return result;
if ( (CmdMod & 1) != 0 )
{
result = IncCBP();
if ( (_DWORD)result != -1 )
{
result = IncCBP();
if ( (_DWORD)result != -1 )
{
if ( *CBfPtr == *(_BYTE *)(CBfPtr - 1LL) )
{
LABEL_6:
v1[0] = NArgmt;
result = InsStr(v1, 1LL);
if ( (_DWORD)result == -1 )
return result;
LABEL_18:
CmdMod = 0;
return 0LL;
}
LABEL_11:
ErrMsg(7LL);
return 0xFFFFFFFFLL;
}
}
}
else
{
if ( CStEnd != CBfPtr + 1LL )
{
if ( *(_BYTE *)(CBfPtr + 1LL) == 27 )
goto LABEL_6;
goto LABEL_11;
}
if ( MStTop < 0 )
{
ErrUTC();
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
DEFAULT ExeI()
{
 unsigned char InChar;
 ;
 if (EStTop > EStBot) {
  if (GetNmA() == (-1)) {
   ;
   return (-1);
  }
  if (CmdMod & '\1') {
   if (IncCBP() == (-1)) {
    ;
    return (-1);
   }
   if (IncCBP() == (-1)) {
    ;
    return (-1);
   }
   if (*CBfPtr != *(CBfPtr-1)) {
    ErrMsg(7);
    ;
    return (-1);
   }
  } else {
   if ((CBfPtr+1) == CStEnd) {
    if (MStTop < 0) {
     ErrUTC();
     ;
     return (-1);
    } else {
     ;
     return 0;
    }
   }
   if (*(CBfPtr+1) != '\033') {
    ErrMsg(7);
    ;
    return (-1);
   }
  }
  InChar = (char)NArgmt;
  if (InsStr(&InChar, (int)1) == (-1)) {
   ;
   return (-1);
  }
 } else {
  if (FindES('\033') == (-1)) {
   ;
   return (-1);
  }
  if (InsStr(ArgPtr, CBfPtr-ArgPtr) == (-1)) {
   ;
   return (-1);
  }
 }
 CmdMod = '\0';
 ;
 return 0;
}

canonical_original_code:
int ExeI()
{
 unsigned char InChar;
 ;
 if (EStTop > EStBot) {
  if (GetNmA() == (-1)) {
   ;
   return (-1);
  }
  if (CmdMod & '\1') {
   if (IncCBP() == (-1)) {
    ;
    return (-1);
   }
   if (IncCBP() == (-1)) {
    ;
    return (-1);
   }
   if (*CBfPtr != *(CBfPtr-1)) {
    ErrMsg(7);
    ;
    return (-1);
   }
  } else {
   if ((CBfPtr+1) == CStEnd) {
    if (MStTop < 0) {
     ErrUTC();
     ;
     return (-1);
    } else {
     ;
     return 0;
    }
   }
   if (*(CBfPtr+1) != '\033') {
    ErrMsg(7);
    ;
    return (-1);
   }
  }
  InChar = (char)NArgmt;
  if (InsStr(&InChar, (int)1) == (-1)) {
   ;
   return (-1);
  }
 } else {
  if (FindES('\033') == (-1)) {
   ;
   return (-1);
  }
  if (InsStr(ArgPtr, CBfPtr-ArgPtr) == (-1)) {
   ;
   return (-1);
  }
 }
 CmdMod = '\0';
 ;
 return 0;
}

variable_types:
InChar
unsigned char


PopMac

decompiled_code:
__int64 PopMac()
{
__int16 v0; // r14
__int16 v1; // r13
int v2; // er12
_QWORD *v3; // rbx
_QWORD *v4; // rbp
__int64 result; // rax

v0 = EStTop;
v1 = EStBot;
if ( EStTop <= EStBot || (result = GetNmA(), (_DWORD)result != -1) )
{
v2 = MStTop;
CStBeg = *((_QWORD *)&MStack + 5 * MStTop);
CBfPtr = *((_QWORD *)&MStack + 5 * MStTop + 1);
CStEnd = *((_QWORD *)&MStack + 5 * MStTop + 2);
EStBot = *((_WORD *)&MStack + 20 * MStTop + 12);
EStTop = *((_WORD *)&MStack + 20 * MStTop + 13);
LStBot = *((_WORD *)&MStack + 20 * MStTop + 14);
LStTop = *((_WORD *)&MStack + 20 * MStTop + 15);
v3 = (_QWORD *)*((_QWORD *)&MStack + 5 * MStTop + 4);
if ( v3 )
{
v4 = v3 + 108;
do
{
if ( *v3 )
((void (*)(void))ZFree)();
v3 += 3;
}
while ( v3 != v4 );
ZFree(*((_QWORD *)&MStack + 5 * v2 + 4));
}
--MStTop;
result = 0LL;
if ( v0 > v1 )
result = PushEx(NArgmt, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int16 v0; // r14
__int16 v1; // r13
int v2; // er12
_QWORD *v3; // rbx
_QWORD *v4; // rbp
__int64 result; // rax

v0 = EStTop;
v1 = EStBot;
if ( EStTop <= EStBot || (result = GetNmA(), (_DWORD)result != -1) )
{
v2 = MStTop;
CStBeg = *((_QWORD *)&MStack + 5 * MStTop);
CBfPtr = *((_QWORD *)&MStack + 5 * MStTop + 1);
CStEnd = *((_QWORD *)&MStack + 5 * MStTop + 2);
EStBot = *((_WORD *)&MStack + 20 * MStTop + 12);
EStTop = *((_WORD *)&MStack + 20 * MStTop + 13);
LStBot = *((_WORD *)&MStack + 20 * MStTop + 14);
LStTop = *((_WORD *)&MStack + 20 * MStTop + 15);
v3 = (_QWORD *)*((_QWORD *)&MStack + 5 * MStTop + 4);
if ( v3 )
{
v4 = v3 + 108;
do
{
if ( *v3 )
((void (*)(void))ZFree)();
v3 += 3;
}
while ( v3 != v4 );
ZFree(*((_QWORD *)&MStack + 5 * v2 + 4));
}
--MStTop;
result = 0LL;
if ( v0 > v1 )
result = PushEx(NArgmt, 0LL);
}
return result;
}

original_code:
DEFAULT PopMac()
{
    WORD i;
    MSptr MSp;
    QRptr QRp;
    BOOLEAN RetVal;
    ;
    RetVal = (EStTop > EStBot);
    if (RetVal) {
        if (GetNmA() == (-1)) {
     ;
     return (-1);
 }
    }
    MSp = &MStack[MStTop];
    CStBeg = MSp->CStBeg;
    CBfPtr = MSp->CBfPtr;
    CStEnd = MSp->CStEnd;
    EStBot = MSp->EStBot;
    EStTop = MSp->EStTop;
    LStBot = MSp->LStBot;
    LStTop = MSp->LStTop;
    if (MSp->QRgstr != (void *)0) {
        for (QRp = MSp->QRgstr, i = 0; i < 36; ++i, ++QRp) {
     if (QRp->Start != (void *)0) {
  ZFree((voidptr)QRp->Start);
     }
 }
 ZFree(MSp->QRgstr);
    }
    --MStTop;
    return ((RetVal) ? PushEx(NArgmt, 0) : 0);
}

canonical_original_code:
int PopMac()
{
    short i;
    struct MStck *MSp;
    struct QReg *QRp;
    int RetVal;
    ;
    RetVal = (EStTop > EStBot);
    if (RetVal) {
        if (GetNmA() == (-1)) {
     ;
     return (-1);
 }
    }
    MSp = &MStack[MStTop];
    CStBeg = MSp->CStBeg;
    CBfPtr = MSp->CBfPtr;
    CStEnd = MSp->CStEnd;
    EStBot = MSp->EStBot;
    EStTop = MSp->EStTop;
    LStBot = MSp->LStBot;
    LStTop = MSp->LStTop;
    if (MSp->QRgstr != (void *)0) {
        for (QRp = MSp->QRgstr, i = 0; i < 36; ++i, ++QRp) {
     if (QRp->Start != (void *)0) {
  ZFree((unsigned char *)QRp->Start);
     }
 }
 ZFree(MSp->QRgstr);
    }
    --MStTop;
    return ((RetVal) ? PushEx(NArgmt, 0) : 0);
}

variable_types: i short

variable_types: struct MStck { unsigned char *CStBeg; unsigned char *CBfPtr; unsigned char *CStEnd; short EStBot; short EStTop; short LStBot; short LStTop; struct QReg { unsigned char *Start; unsigned char *End_P1; long Number; } *QRgstr; } *

variable_types: RetVal int

user_defined_types: struct MStck { unsigned char *CStBeg; unsigned char *CBfPtr; unsigned char *CStEnd; short EStBot; short EStTop; short LStBot; short LStTop; struct QReg *QRgstr; }


ExeLBr

decompiled_code:
__int64 ExeLBr()
{
__int64 result; // rax
__int16 v1; // ax
_QWORD *v2; // rbp
__int64 v3; // rbx

result = IncCBP();
if ( (_DWORD)result != -1 )
{
result = FindQR();
if ( (_DWORD)result != -1 )
{
v1 = QStTop + 1;
QStTop = v1;
if ( v1 > 31 )
{
ErrMsg(32LL);
return 0xFFFFFFFFLL;
}
v2 = (_QWORD *)QR;
QR = (char *)&QStack + 24 * v1;
v3 = v2[1] - *v2;
if ( *((_DWORD *)v2 + 2) - *(_DWORD *)v2 > 0 )
{
result = MakRom((unsigned int)v3);
if ( (_DWORD)result == -1 )
{
QR = v2;
--QStTop;
return result;
}
ZCpyBl(*QR, *v2, (unsigned int)v3);
*(_QWORD *)(QR + 8LL) = *QR + (int)v3;
}
*(_QWORD *)(QR + 16LL) = v2[2];
QR = v2;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int16 v1; // ax
_QWORD *v2; // rbp
__int64 v3; // rbx

result = IncCBP();
if ( (_DWORD)result != -1 )
{
result = FindQR();
if ( (_DWORD)result != -1 )
{
v1 = QStTop + 1;
QStTop = v1;
if ( v1 > 31 )
{
ErrMsg(32LL);
return 0xFFFFFFFFLL;
}
v2 = (_QWORD *)QR;
QR = (char *)&QStack + 24 * v1;
v3 = v2[1] - *v2;
if ( *((_DWORD *)v2 + 2) - *(_DWORD *)v2 > 0 )
{
result = MakRom((unsigned int)v3);
if ( (_DWORD)result == -1 )
{
QR = v2;
--QStTop;
return result;
}
ZCpyBl(*QR, *v2, (unsigned int)v3);
*(_QWORD *)(QR + 8LL) = *QR + (int)v3;
}
*(_QWORD *)(QR + 16LL) = v2[2];
QR = v2;
result = 0LL;
}
}
return result;
}

original_code:
DEFAULT ExeLBr()
{
 QRptr TmpQRp;
 int TmpSiz;
 if (IncCBP() == (-1)) {
  ;
  return (-1);
 }
 if (FindQR() == (-1)) {
  ;
  return (-1);
 }
 if (++QStTop >= 32) {
  ErrMsg(32);
  ;
  return (-1);
 }
 TmpQRp = QR;
 QR = &QStack[QStTop];
 TmpSiz = TmpQRp->End_P1 - TmpQRp->Start;
 if (TmpSiz > 0) {
  if (MakRom((SIZE_T)TmpSiz) == (-1)) {
   QR = TmpQRp;
   --QStTop;
   ;
   return (-1);
  }
  ZCpyBl((QR->Start),(TmpQRp->Start),((SIZE_T) TmpSiz));
  QR->End_P1 = QR->Start + TmpSiz;
 }
 QR->Number = TmpQRp->Number;
 QR = TmpQRp;
 ;
 return 0;
}

canonical_original_code:
int ExeLBr()
{
 struct QReg *TmpQRp;
 int TmpSiz;
 if (IncCBP() == (-1)) {
  ;
  return (-1);
 }
 if (FindQR() == (-1)) {
  ;
  return (-1);
 }
 if (++QStTop >= 32) {
  ErrMsg(32);
  ;
  return (-1);
 }
 TmpQRp = QR;
 QR = &QStack[QStTop];
 TmpSiz = TmpQRp->End_P1 - TmpQRp->Start;
 if (TmpSiz > 0) {
  if (MakRom((unsigned int)TmpSiz) == (-1)) {
   QR = TmpQRp;
   --QStTop;
   ;
   return (-1);
  }
  ZCpyBl((QR->Start),(TmpQRp->Start),((unsigned int) TmpSiz));
  QR->End_P1 = QR->Start + TmpSiz;
 }
 QR->Number = TmpQRp->Number;
 QR = TmpQRp;
 ;
 return 0;
}

variable_types: struct QReg { unsigned char *Start; unsigned char *End_P1; long Number; } *

variable_types: TmpSiz int


ExeCtP

decompiled_code:
__int64 ExeCtP()
{
return ExeIll();
}

canonical_decompiled_code:
__int64 func0()
{
return ExeIll();
}

original_code:
DEFAULT ExeCtP()
{
 return (ExeIll ());
}

canonical_original_code:
int ExeCtP()
{
 return (ExeIll ());
}


TypESt

decompiled_code:
__int64 TypESt()
{
TypBuf(CStBeg, CBfPtr);
return ZDspBf(&unk_37, 3LL);
}

canonical_decompiled_code:
__int64 func0()
{
TypBuf(CStBeg, CBfPtr);
return ZDspBf(&unk_37, 3LL);
}

original_code:
void TypESt()
{
 TypBuf(CStBeg,CBfPtr);
 ZDspBf("?\r\n", 3);
}

return_type: void


ClenUp

decompiled_code:
__int64 ClenUp()
{
char *v0; // rbx
char *v1; // rbx

ZIClos(0LL);
ZIClos(1LL);
ZOClDe(0LL);
ZOClDe(1LL);
if ( CBfBeg )
ZFree();
if ( DBfBeg )
ZFree();
if ( EBfBeg )
ZFree();
if ( FBfBeg )
ZFree();
if ( SBfBeg )
ZFree();
v0 = (char *)&QRgstr;
do
{
if ( *(_QWORD *)v0 )
ZFree();
v0 += 24;
}
while ( v0 != (char *)&QRgstr + 1728 );
v1 = (char *)&QStack;
do
{
if ( *(_QWORD *)v1 )
ZFree();
v1 += 24;
}
while ( v1 != (char *)&QStack + 768 );
return ZClnUp();
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // rbx
char *v1; // rbx

ZIClos(0LL);
ZIClos(1LL);
ZOClDe(0LL);
ZOClDe(1LL);
if ( CBfBeg )
ZFree();
if ( DBfBeg )
ZFree();
if ( EBfBeg )
ZFree();
if ( FBfBeg )
ZFree();
if ( SBfBeg )
ZFree();
v0 = (char *)&QRgstr;
do
{
if ( *(_QWORD *)v0 )
ZFree();
v0 += 24;
}
while ( v0 != (char *)&QRgstr + 1728 );
v1 = (char *)&QStack;
do
{
if ( *(_QWORD *)v1 )
ZFree();
v1 += 24;
}
while ( v1 != (char *)&QStack + 768 );
return ZClnUp();
}

original_code:
void ClenUp (void)
{
 QRptr QRp;
 int i;
 ZIClos(0);
 ZIClos(1);
 ZOClDe(0);
 ZOClDe(1);
 if (CBfBeg) ZFree((voidptr)CBfBeg);
 if (DBfBeg) ZFree((voidptr)DBfBeg);
 if (EBfBeg) ZFree((voidptr)EBfBeg);
 if (FBfBeg) ZFree((voidptr)FBfBeg);
 if (SBfBeg) ZFree((voidptr)SBfBeg);
 for (QRp = QRgstr, i = 0; i < 72; ++i, ++QRp) {
  if (QRp->Start != (void *)0) {
   ZFree((voidptr)QRp->Start);
  }
 }
 for (QRp = QStack, i = 0; i < 32; ++i, ++QRp) {
  if (QRp->Start != (void *)0) {
   ZFree((voidptr)QRp->Start);
  }
 }
 ZClnUp();
}

canonical_original_code:
void ClenUp()
{
 struct QReg *QRp;
 int i;
 ZIClos(0);
 ZIClos(1);
 ZOClDe(0);
 ZOClDe(1);
 if (CBfBeg) ZFree((unsigned char *)CBfBeg);
 if (DBfBeg) ZFree((unsigned char *)DBfBeg);
 if (EBfBeg) ZFree((unsigned char *)EBfBeg);
 if (FBfBeg) ZFree((unsigned char *)FBfBeg);
 if (SBfBeg) ZFree((unsigned char *)SBfBeg);
 for (QRp = QRgstr, i = 0; i < 72; ++i, ++QRp) {
  if (QRp->Start != (void *)0) {
   ZFree((unsigned char *)QRp->Start);
  }
 }
 for (QRp = QStack, i = 0; i < 32; ++i, ++QRp) {
  if (QRp->Start != (void *)0) {
   ZFree((unsigned char *)QRp->Start);
  }
 }
 ZClnUp();
}

variable_types: i int

user_defined_types: struct QReg { unsigned char *Start; unsigned char *End_P1; long Number; }


repo: rnakano/Suzuka

decompiled_code:
char *__fastcall sk_http_parse_header(char *a1)
{
signed int v1; // eax
char *v2; // rbx
signed int v3; // ebp
signed int v4; // eax
const char *v5; // rdx
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
char v11; // al
bool v12; // cf
bool v13; // zf
const char *v14; // rdi
__int64 v15; // rcx
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (unsigned int)strtok_r(a1, " \r\n", save_ptr);
if ( !v1 )
return 0LL;
v2 = 0LL;
if ( !strcmp((const char *)v1, "GET") )
{
v3 = (unsigned int)strtok_r(0LL, " \r\n", save_ptr);
if ( v3 )
{
v4 = (unsigned int)strtok_r(0LL, " \r\n", save_ptr);
v5 = (const char *)v4;
v6 = 0;
v7 = v4 == 0;
if ( v4 )
{
v8 = "HTTP/1.1";
v9 = 9LL;
v10 = (const char *)v4;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
goto LABEL_13;
v14 = "HTTP/1.0";
v15 = 9LL;
v10 = v5;
do
{
if ( !v15 )
break;
v12 = *v10 < (unsigned int)*v14;
v13 = *v10++ == *v14++;
--v15;
}
while ( v13 );
if ( (!v12 && !v13) != v12 )
{
v2 = 0LL;
}
else
{
LABEL_13:
v2 = (char *)sk_malloc(256LL, v10, v5);
strncpy(v2, (const char *)v3, 0x100uLL);
}
}
else
{
v2 = 0LL;
}
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
signed int v1; // eax
char *v2; // rbx
signed int v3; // ebp
signed int v4; // eax
const char *v5; // rdx
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
char v11; // al
bool v12; // cf
bool v13; // zf
const char *v14; // rdi
__int64 v15; // rcx
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (unsigned int)strtok_r(a1, " \r\n", save_ptr);
if ( !v1 )
return 0LL;
v2 = 0LL;
if ( !strcmp((const char *)v1, "GET") )
{
v3 = (unsigned int)strtok_r(0LL, " \r\n", save_ptr);
if ( v3 )
{
v4 = (unsigned int)strtok_r(0LL, " \r\n", save_ptr);
v5 = (const char *)v4;
v6 = 0;
v7 = v4 == 0;
if ( v4 )
{
v8 = "HTTP/1.1";
v9 = 9LL;
v10 = (const char *)v4;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
v11 = (!v6 && !v7) - v6;
v12 = 0;
v13 = v11 == 0;
if ( !v11 )
goto LABEL_13;
v14 = "HTTP/1.0";
v15 = 9LL;
v10 = v5;
do
{
if ( !v15 )
break;
v12 = *v10 < (unsigned int)*v14;
v13 = *v10++ == *v14++;
--v15;
}
while ( v13 );
if ( (!v12 && !v13) != v12 )
{
v2 = 0LL;
}
else
{
LABEL_13:
v2 = (char *)sk_malloc(256LL, v10, v5);
strncpy(v2, (const char *)v3, 0x100uLL);
}
}
else
{
v2 = 0LL;
}
}
}
return v2;
}

original_code:
sk_http_header* sk_http_parse_header(char* str)
{
  char *type, *path, *version;
  char* saveptr;
  type = strtok_r(str, " \r\n", &saveptr);
  if(type == ((void *)0)) return ((void *)0);
  if(strcmp(type, "GET") != 0) return ((void *)0);
  path = strtok_r(((void *)0), " \r\n", &saveptr);
  if(path == ((void *)0)) return ((void *)0);
  version = strtok_r(((void *)0), " \r\n", &saveptr);
  if(version == ((void *)0)) return ((void *)0);
  if(strcmp(version, "HTTP/1.1") != 0 && strcmp(version, "HTTP/1.0") != 0) return ((void *)0);
  sk_http_header *header = sk_malloc(sizeof(sk_http_header));
  strncpy(header->path, path, 256);
  return header;
}

canonical_original_code:
struct sk_http_header *sk_http_parse_header(char *str)
{
  char *type; char *path; char *version;
  char *saveptr;
  type = strtok_r(str, " \r\n", &saveptr);
  if(type == ((void *)0)) return ((void *)0);
  if(strcmp(type, "GET") != 0) return ((void *)0);
  path = strtok_r(((void *)0), " \r\n", &saveptr);
  if(path == ((void *)0)) return ((void *)0);
  version = strtok_r(((void *)0), " \r\n", &saveptr);
  if(version == ((void *)0)) return ((void *)0);
  if(strcmp(version, "HTTP/1.1") != 0 && strcmp(version, "HTTP/1.0") != 0) return ((void *)0);
  struct sk_http_header *header = sk_malloc(sizeof(sk_http_header));
  strncpy(header->path, path, 256);
  return header;
}

variable_types:
str
char *

variable_types:
type
char *

variable_types:
path
char *

variable_types:
version
char *

variable_types:
saveptr
char *

variable_types: struct sk_http_header { char path[256]; } *


decompiled_code:
__int64 sk_http_header_free()
{
return sk_free();
}

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

original_code:
void sk_http_header_free(sk_http_header* header)
{
  sk_free(header);
}

canonical_original_code:
void sk_http_header_free(struct sk_http_header *header)
{
  sk_free(header);
}

user_defined_types: struct sk_http_header { char path[256]; }


decompiled_code:
int __fastcall sk_http_write_response_header(const char **a1, char *a2, size_t a3)
{
return snprintf(
a2,
a3,
"HTTP/1.1 %d OK\r\nContent-Type: %s\r\nContent-Length: %lld\r\nConnection: close\r\nServer: suzuka\r\n\r\n",
*(unsigned __int16 *)a1,
a1[1],
a1[2]);
}

canonical_decompiled_code:
int __fastcall func2(const char **a1, char *a2, size_t a3)
{
return snprintf(
a2,
a3,
"HTTP/1.1 %d OK\r\nContent-Type: %s\r\nContent-Length: %lld\r\nConnection: close\r\nServer: suzuka\r\n\r\n",
*(unsigned __int16 *)a1,
a1[1],
a1[2]);
}

original_code:
void sk_http_write_response_header(sk_http_response* response, char* buff, size_t buflen)
{
  snprintf(buff,
           buflen,
          "HTTP/1.1 %d OK" "\r\n"
          "Content-Type: %s" "\r\n"
          "Content-Length: %lld" "\r\n"
          "Connection: close" "\r\n"
          "Server: suzuka" "\r\n" "\r\n",
          response->status_code,
          response->content_type,
          response->content_length);
}

canonical_original_code:
void sk_http_write_response_header(struct sk_http_response *response, char *buff, unsigned long buflen)
{
  snprintf(buff,
           buflen,
          "HTTP/1.1 %d OK" "\r\n"
          "Content-Type: %s" "\r\n"
          "Content-Length: %lld" "\r\n"
          "Connection: close" "\r\n"
          "Server: suzuka" "\r\n" "\r\n",
          response->status_code,
          response->content_type,
          response->content_length);
}

variable_types: struct sk_http_response { unsigned short status_code; char *content_type; unsigned long content_length; } *

variable_types:
buff
char *

variable_types:
buflen
unsigned long


decompiled_code:
char __fastcall sk_image_parse_term(char *a1, _DWORD *a2)
{
int v2; // eax
bool v3; // zf
int v5; // [rsp+4h] [rbp-14h] BYREF
char *save_ptr; // [rsp+8h] [rbp-10h] BYREF

v2 = (unsigned int)strtok_r(a1, "=", &save_ptr);
if ( v2 )
{
if ( !strcmp((const char *)v2, "w") )
{
v3 = strcmp(save_ptr, "auto") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
a2[2] |= 2u;
}
else
{
v2 = _isoc99_sscanf(save_ptr, "%ud", &v5);
if ( v2 > 0 )
{
a2[2] &= 0xFFFFFFFD;
LOBYTE(v2) = v5;
*a2 = v5;
}
}
}
else
{
v3 = strcmp((const char *)v2, "h") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
v3 = strcmp(save_ptr, "auto") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
a2[2] |= 4u;
}
else
{
v2 = _isoc99_sscanf(save_ptr, "%ud", &v5);
if ( v2 > 0 )
{
a2[2] &= 0xFFFFFFFB;
LOBYTE(v2) = v5;
a2[1] = v5;
}
}
}
}
}
return v2;
}

canonical_decompiled_code:
char __fastcall func0(char *a1, _DWORD *a2)
{
int v2; // eax
bool v3; // zf
int v5; // [rsp+4h] [rbp-14h] BYREF
char *save_ptr; // [rsp+8h] [rbp-10h] BYREF

v2 = (unsigned int)strtok_r(a1, "=", &save_ptr);
if ( v2 )
{
if ( !strcmp((const char *)v2, "w") )
{
v3 = strcmp(save_ptr, "auto") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
a2[2] |= 2u;
}
else
{
v2 = _isoc99_sscanf(save_ptr, "%ud", &v5);
if ( v2 > 0 )
{
a2[2] &= 0xFFFFFFFD;
LOBYTE(v2) = v5;
*a2 = v5;
}
}
}
else
{
v3 = strcmp((const char *)v2, "h") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
v3 = strcmp(save_ptr, "auto") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
{
a2[2] |= 4u;
}
else
{
v2 = _isoc99_sscanf(save_ptr, "%ud", &v5);
if ( v2 > 0 )
{
a2[2] &= 0xFFFFFFFB;
LOBYTE(v2) = v5;
a2[1] = v5;
}
}
}
}
}
return v2;
}

original_code:
void sk_image_parse_term(char* term, sk_image_request* result)
{
  char* saveptr;
  char* name = strtok_r(term, "=", &saveptr);
  if(name == ((void *)0)) return;
  if(strcmp(name, "w") == 0) {
    if(strcmp(saveptr, "auto") == 0) {
      result->convert_flag |= 0b0010;
    } else {
      uint32_t width;
      if(sscanf(saveptr, "%ud", &width) > 0) {
        result->convert_flag &= ~0b0010;
        result->width = width;
      }
    }
  } else if(strcmp(name, "h") == 0) {
    if(strcmp(saveptr, "auto") == 0) {
      result->convert_flag |= 0b0100;
    } else {
      uint32_t height;
      if(sscanf(saveptr, "%ud", &height) > 0) {
        result->convert_flag &= ~0b0100;
        result->height = height;
      }
    }
  }
}

canonical_original_code:
void sk_image_parse_term(char *term, struct sk_image_request *result)
{
  char *saveptr;
  char *name = strtok_r(term, "=", &saveptr);
  if(name == ((void *)0)) return;
  if(strcmp(name, "w") == 0) {
    if(strcmp(saveptr, "auto") == 0) {
      result->convert_flag |= 0b0010;
    } else {
      unsigned int width;
      if(sscanf(saveptr, "%ud", &width) > 0) {
        result->convert_flag &= ~0b0010;
        result->width = width;
      }
    }
  } else if(strcmp(name, "h") == 0) {
    if(strcmp(saveptr, "auto") == 0) {
      result->convert_flag |= 0b0100;
    } else {
      unsigned int height;
      if(sscanf(saveptr, "%ud", &height) > 0) {
        result->convert_flag &= ~0b0100;
        result->height = height;
      }
    }
  }
}

variable_types:
term
char *

variable_types: struct sk_image_request { unsigned int width; unsigned int convert_flag; char *path; } *

variable_types:
name
char *

variable_types:
width
unsigned int

variable_types:
height
unsigned int


decompiled_code:
char *__fastcall sk_image_parse_request(char *a1, __int64 a2)
{
char *result; // rax
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

result = strtok_r(a1, "?", save_ptr);
if ( save_ptr[0] )
{
*(_QWORD *)(a2 + 16) = (int)result;
while ( 1 )
{
result = strtok_r(0LL, "&", save_ptr);
if ( !(_DWORD)result )
break;
sk_image_parse_term((char *)(int)result, (_DWORD *)a2);
}
}
else
{
*(_QWORD *)(a2 + 16) = a1;
*(_DWORD *)(a2 + 8) |= 1u;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, __int64 a2)
{
char *result; // rax
char *save_ptr[4]; // [rsp+8h] [rbp-20h] BYREF

result = strtok_r(a1, "?", save_ptr);
if ( save_ptr[0] )
{
*(_QWORD *)(a2 + 16) = (int)result;
while ( 1 )
{
result = strtok_r(0LL, "&", save_ptr);
if ( !(_DWORD)result )
break;
func0((char *)(int)result, (_DWORD *)a2);
}
}
else
{
*(_QWORD *)(a2 + 16) = a1;
*(_DWORD *)(a2 + 8) |= 1u;
}
return result;
}

original_code:
void sk_image_parse_request(char* request, sk_image_request* result)
{
  char* saveptr;
  char* path = strtok_r(request, "?", &saveptr);
  if(saveptr == ((void *)0)) {
    result->path = request;
    result->convert_flag |= 0b0001;
    return;
  }
  result->path = path;
  char* term;
  while((term = strtok_r(((void *)0), "&", &saveptr)) != ((void *)0)) {
    sk_image_parse_term(term, result);
  }
}

canonical_original_code:
void sk_image_parse_request(char *request, struct sk_image_request *result)
{
  char *saveptr;
  char *path = strtok_r(request, "?", &saveptr);
  if(saveptr == ((void *)0)) {
    result->path = request;
    result->convert_flag |= 0b0001;
    return;
  }
  result->path = path;
  char *term;
  while((term = strtok_r(((void *)0), "&", &saveptr)) != ((void *)0)) {
    sk_image_parse_term(term, result);
  }
}

variable_types:
request
char *

user_defined_types: struct sk_image_request { unsigned int width; unsigned int convert_flag; char *path; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v4; // [rsp+0h] [rbp-28h] BYREF
const char *v5; // [rsp+8h] [rbp-20h]
const char *v6; // [rsp+10h] [rbp-18h]
void *v7; // [rsp+18h] [rbp-10h]

_sysv_signal(13, (__sighandler_t)((char *)main + 1));
v4 = 8080;
v5 = "127.0.0.1";
v7 = &sk_handler_simple_send;
v6 = "../public";
sk_server_start(&v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  signal(13 , ((__sighandler_t) 1));
  sk_server server;
  server.port = 8080;
  server.addr = "127.0.0.1";
  server.handler = sk_handler_simple_send;
  server.document_root = "../public";
  sk_server_start(&server);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  signal(13 , ((void (*)(int)) 1));
  struct sk_server_T server;
  server.port = 8080;
  server.addr = "127.0.0.1";
  server.handler = sk_handler_simple_send;
  server.document_root = "../public";
  sk_server_start(&server);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct sk_server_T { unsigned short port; char *addr; char *document_root; void (*handler)(struct sk_server_T *, int); }


decompiled_code:
int __fastcall sk_log_error(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void sk_log_error(char* str)
{
  fprintf(stderr, "%s\n", str);
}

canonical_original_code:
void sk_log_error(char *str)
{
  fprintf(stderr, "%s\n", str);
}

variable_types:
str
char *


decompiled_code:
void __fastcall sk_log_perror(const char *a1)
{
perror(a1);
}

canonical_decompiled_code:
void __fastcall func1(const char *a1)
{
perror(a1);
}

original_code:
void sk_log_perror(char* str)
{
  perror(str);
}

canonical_original_code:
void sk_log_perror(char *str)
{
  perror(str);
}


decompiled_code:
int __fastcall sk_log_debug(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void sk_log_debug(char* str)
{
  fprintf(stderr, "%s\n", str);
}

canonical_original_code:
void sk_log_debug(char *str)
{
  fprintf(stderr, "%s\n", str);
}


decompiled_code:
const char *__fastcall sk_file_content_type_ext(const char *a1)
{
const char *v1; // rcx

v1 = "image/jpeg";
if ( strcmp(a1, "jpg") )
{
v1 = "image/jpeg";
if ( strcmp(a1, "jpeg") )
{
v1 = "text/html";
if ( !strcmp(a1, "png") )
v1 = "image/png";
}
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
const char *v1; // rcx

v1 = "image/jpeg";
if ( strcmp(a1, "jpg") )
{
v1 = "image/jpeg";
if ( strcmp(a1, "jpeg") )
{
v1 = "text/html";
if ( !strcmp(a1, "png") )
v1 = "image/png";
}
}
return v1;
}

original_code:
const char* sk_file_content_type_ext(const char* ext)
{
  if(strcmp(ext, "jpg") == 0) {
    return "image/jpeg";
  } else if(strcmp(ext, "jpeg") == 0) {
    return "image/jpeg";
  } else if(strcmp(ext, "png") == 0) {
    return "image/png";
  }
  return "text/html";
}

canonical_original_code:
char *sk_file_content_type_ext(char *ext)
{
  if(strcmp(ext, "jpg") == 0) {
    return "image/jpeg";
  } else if(strcmp(ext, "jpeg") == 0) {
    return "image/jpeg";
  } else if(strcmp(ext, "png") == 0) {
    return "image/png";
  }
  return "text/html";
}

variable_types:
ext
char *

return_type: char *


decompiled_code:
const char *__fastcall sk_file_extname(const char *a1)
{
__int64 v1; // rax

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 < 0 )
return (const char *)&unk_148;
v1 = (int)v1;
while ( a1[v1] != 46 )
{
if ( (int)--v1 < 0 )
return (const char *)&unk_148;
}
return &a1[v1 + 1];
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
__int64 v1; // rax

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 < 0 )
return (const char *)&unk_148;
v1 = (int)v1;
while ( a1[v1] != 46 )
{
if ( (int)--v1 < 0 )
return (const char *)&unk_148;
}
return &a1[v1 + 1];
}

original_code:
const char* sk_file_extname(const char* path)
{
  int n = strlen(path);
  for (int i = n-1; i >= 0; i--){
    if(path[i] == '.') {
      return &path[i+1];
    }
  }
  return "";
}

canonical_original_code:
char *sk_file_extname(char *path)
{
  int n = strlen(path);
  for (int i = n-1; i >= 0; i--){
    if(path[i] == '.') {
      return &path[i+1];
    }
  }
  return "";
}

variable_types:
path
char *

variable_types: n int

variable_types: i int


decompiled_code:
const char *__fastcall sk_file_content_type(const char *a1)
{
const char *v1; // rax

v1 = sk_file_extname(a1);
return sk_file_content_type_ext(v1);
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
const char *v1; // rax

v1 = func1(a1);
return func0(v1);
}

original_code:
const char* sk_file_content_type(const char* path)
{
  const char* ext = sk_file_extname(path);
  return sk_file_content_type_ext(ext);
}

canonical_original_code:
char *sk_file_content_type(char *path)
{
  char *ext = sk_file_extname(path);
  return sk_file_content_type_ext(ext);
}


decompiled_code:
__int64 __fastcall sk_file_validate_path(const char *a1)
{
__int64 result; // rax
int v2; // edx
const char *v3; // rax
char v4; // cl

result = 0LL;
if ( *a1 == 47 )
{
v2 = strlen(a1);
if ( v2 <= 0 )
return 1LL;
v3 = a1;
while ( 1 )
{
if ( *v3 == 47 )
{
v4 = v3[1];
if ( v4 == 47 )
return 0LL;
if ( v4 && v3[2] == 46 && v4 == 46 )
return 0LL;
}
if ( ++v3 == &a1[v2 - 1 + 1] )
return 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
__int64 result; // rax
int v2; // edx
const char *v3; // rax
char v4; // cl

result = 0LL;
if ( *a1 == 47 )
{
v2 = strlen(a1);
if ( v2 <= 0 )
return 1LL;
v3 = a1;
while ( 1 )
{
if ( *v3 == 47 )
{
v4 = v3[1];
if ( v4 == 47 )
return 0LL;
if ( v4 && v3[2] == 46 && v4 == 46 )
return 0LL;
}
if ( ++v3 == &a1[v2 - 1 + 1] )
return 1LL;
}
}
return result;
}

original_code:
_Bool sk_file_validate_path(const char* path)
{
  if(path[0] != '/') {
    return 0;
  }
  int n = strlen(path);
  for (int i = 0; i < n; i++){
    if(path[i] == '/') {
      if(path[i+1] && path[i+1] == '/') {
        return 0;
      }
      if(path[i+1] && path[i+2] && path[i+1] == '.' && path[i+2] == '.') {
        return 0;
      }
    }
  }
  return 1;
}

canonical_original_code:
_Bool sk_file_validate_path(char *path)
{
  if(path[0] != '/') {
    return 0;
  }
  int n = strlen(path);
  for (int i = 0; i < n; i++){
    if(path[i] == '/') {
      if(path[i+1] && path[i+1] == '/') {
        return 0;
      }
      if(path[i+1] && path[i+2] && path[i+1] == '.' && path[i+2] == '.') {
        return 0;
      }
    }
  }
  return 1;
}


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

result = malloc(a1);
if ( !result )
{
sk_log_error("Cannot allocate memory.");
exit(1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
sk_log_error("Cannot allocate memory.");
exit(1);
}
return result;
}

original_code:
void* sk_malloc(size_t size) {
  void* ptr = malloc(size);
  if(ptr == ((void *)0)) {
    sk_log_error("Cannot allocate memory.");
    exit(1);
  }
  return ptr;
}

canonical_original_code:
void *sk_malloc(unsigned long size) {
  void *ptr = malloc(size);
  if(ptr == ((void *)0)) {
    sk_log_error("Cannot allocate memory.");
    exit(1);
  }
  return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


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

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

original_code:
void sk_free(void* ptr) {
  free(ptr);
}

canonical_original_code:
void sk_free(void *ptr) {
  free(ptr);
}


decompiled_code:
void __fastcall __noreturn sk_server_start(__int64 a1)
{
int v1; // eax
int v2; // er12
int v3; // ebx
char optval; // [rsp+Fh] [rbp-49h] BYREF
struct sockaddr v5; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 0);
if ( v1 >= 0 )
{
v2 = v1;
addr_len[0] = 16;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(*(_WORD *)a1);
*(_DWORD *)&addr.sa_data[2] = 0;
optval = 1;
setsockopt(v2, 1, 2, &optval, 1u);
if ( bind(v2, &addr, 0x10u) >= 0 )
{
if ( listen(v2, 128) < 0 )
{
sk_log_perror("cannot listen");
exit(1);
}
while ( 1 )
{
v3 = accept(v2, &v5, addr_len);
if ( v3 < 0 )
sk_log_perror("cannot accept");
(*(void (__fastcall **)(__int64, _QWORD))(a1 + 24))(a1, (unsigned int)v3);
}
}
sk_log_perror("cannot bind");
exit(1);
}
sk_log_perror("cannot open server socket");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1)
{
int v1; // eax
int v2; // er12
int v3; // ebx
char optval; // [rsp+Fh] [rbp-49h] BYREF
struct sockaddr v5; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

v1 = socket(2, 1, 0);
if ( v1 >= 0 )
{
v2 = v1;
addr_len[0] = 16;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(*(_WORD *)a1);
*(_DWORD *)&addr.sa_data[2] = 0;
optval = 1;
setsockopt(v2, 1, 2, &optval, 1u);
if ( bind(v2, &addr, 0x10u) >= 0 )
{
if ( listen(v2, 128) < 0 )
{
sk_log_perror("cannot listen");
exit(1);
}
while ( 1 )
{
v3 = accept(v2, &v5, addr_len);
if ( v3 < 0 )
sk_log_perror("cannot accept");
(*(void (__fastcall **)(__int64, _QWORD))(a1 + 24))(a1, (unsigned int)v3);
}
}
sk_log_perror("cannot bind");
exit(1);
}
sk_log_perror("cannot open server socket");
exit(1);
}

original_code:
void sk_server_start(sk_server* server)
{
  int server_sock;
  if((server_sock = socket(2, SOCK_STREAM, 0)) < 0){
    sk_log_perror("cannot open server socket");
    exit(1);
  }
  socklen_t sin_siz = sizeof(struct sockaddr_in);
  struct sockaddr_in serv, clt;
  serv.sin_family = 2;
  serv.sin_port = htons(server->port);
  serv.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  char yes = 1;
  setsockopt(server_sock, 1, 2, (const char*)&yes, sizeof(yes));
  if(bind(server_sock, (struct sockaddr*)&serv, sizeof(serv)) < 0){
    sk_log_perror("cannot bind");
    exit(1);
  }
  if(listen(server_sock, 128) < 0){
    sk_log_perror("cannot listen");
    exit(1);
  }
  int client_sock;
  while(1) {
    if((client_sock = accept(server_sock, (struct sockaddr*)&clt, &sin_siz)) < 0){
      sk_log_perror("cannot accept");
    }
    server->handler(server, client_sock);
  }
}

canonical_original_code:
void sk_server_start(struct sk_server_T *server)
{
  int server_sock;
  if((server_sock = socket(2, SOCK_STREAM, 0)) < 0){
    sk_log_perror("cannot open server socket");
    exit(1);
  }
  unsigned int sin_siz = sizeof(struct sockaddr_in);
  struct sockaddr_in serv; struct sockaddr_in clt;
  serv.sin_family = 2;
  serv.sin_port = htons(server->port);
  serv.sin_addr.s_addr = ((unsigned int) 0x00000000);
  char yes = 1;
  setsockopt(server_sock, 1, 2, (char *)&yes, sizeof(yes));
  if(bind(server_sock, (struct sockaddr *)&serv, sizeof(serv)) < 0){
    sk_log_perror("cannot bind");
    exit(1);
  }
  if(listen(server_sock, 128) < 0){
    sk_log_perror("cannot listen");
    exit(1);
  }
  int client_sock;
  while(1) {
    if((client_sock = accept(server_sock, (struct sockaddr *)&clt, &sin_siz)) < 0){
      sk_log_perror("cannot accept");
    }
    server->handler(server, client_sock);
  }
}

variable_types: struct sk_server_T { unsigned short port; char *addr; char *document_root; void (*handler)(struct sk_server_T *, int); } *

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

variable_types: yes char

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

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


repo: rnakano/amitahash

decompiled_code:
__int64 __fastcall ah_table_hash(const char *a1, unsigned __int64 a2)
{
return (unsigned int)(a2 * *a1 * a1[strlen(a1) >> 1] % a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, unsigned __int64 a2)
{
return (unsigned int)(a2 * *a1 * a1[strlen(a1) >> 1] % a2);
}

original_code:
hash_code ah_table_hash(char* key, ulong size)
{
  ulong l = strlen(key);
  return (key[0] * key[l/2] * size) % size;
}

canonical_original_code:
unsigned int ah_table_hash(char *key, unsigned long size)
{
  unsigned long l = strlen(key);
  return (key[0] * key[l/2] * size) % size;
}

variable_types:
key
char *

variable_types:
l
unsigned long

return_type: unsigned int


decompiled_code:
__int64 __fastcall ah_table_set(_QWORD *a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
signed int v5; // eax

v4 = *a1 + 8LL * (unsigned int)ah_table_hash(a2, a1[2]);
v5 = (unsigned int)strdup(a2);
return ah_bucket_insert(v4, v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
signed int v5; // eax

v4 = *a1 + 8LL * (unsigned int)func7(a2, a1[2]);
v5 = (unsigned int)strdup(a2);
return func14(v4, v5, a3);
}

original_code:
void ah_table_set(ah_table* table, char* key, char* value)
{
  hash_code hash = ah_table_hash(key, table->size);
  ah_bucket** bucket = & (table->data[hash]);
  ah_bucket_insert(bucket, strdup(key), value);
}

canonical_original_code:
void ah_table_set(struct ah_t_table *table, char *key, char *value)
{
  unsigned int hash = ah_table_hash(key, table->size);
  struct ah_t_bucket **bucket = & (table->data[hash]);
  ah_bucket_insert(bucket, strdup(key), value);
}

variable_types: struct ah_t_table { struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; } **data; unsigned long current; unsigned long size; } *

variable_types:
value
char *

variable_types:
hash
unsigned int

user_defined_types: struct ah_t_table { struct ah_t_bucket **data; unsigned long current; unsigned long size; }


decompiled_code:
__int64 __fastcall ah_table_get(_QWORD *a1, const char *a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = ah_table_hash(a2, a1[2]);
result = ah_bucket_search(*(_QWORD *)(*a1 + 8LL * v2), a2);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, const char *a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = func7(a2, a1[2]);
result = func15(*(_QWORD *)(*a1 + 8LL * v2), a2);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
char* ah_table_get(ah_table* table, char* key)
{
  hash_code hash = ah_table_hash(key, table->size);
  ah_bucket* bucket = (table->data[hash]);
  ah_bucket* find = ah_bucket_search(bucket, key);
  if(find) {
    return find->value;
  } else {
    return ((void *)0);
  }
}

canonical_original_code:
char *ah_table_get(struct ah_t_table *table, char *key)
{
  unsigned int hash = ah_table_hash(key, table->size);
  struct ah_t_bucket *bucket = (table->data[hash]);
  struct ah_t_bucket *find = ah_bucket_search(bucket, key);
  if(find) {
    return find->value;
  } else {
    return ((void *)0);
  }
}

variable_types: struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; } *


decompiled_code:
__int64 __fastcall ah_table_remove(_QWORD *a1, const char *a2)
{
unsigned int v2; // eax

v2 = ah_table_hash(a2, a1[2]);
return ah_bucket_remove(*a1 + 8LL * v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, const char *a2)
{
unsigned int v2; // eax

v2 = func7(a2, a1[2]);
return func22(*a1 + 8LL * v2, a2);
}

original_code:
void ah_table_remove(ah_table* table, char* key)
{
  hash_code hash = ah_table_hash(key, table->size);
  ah_bucket** bucket = & (table->data[hash]);
  ah_bucket_remove(bucket, key);
}

canonical_original_code:
void ah_table_remove(struct ah_t_table *table, char *key)
{
  unsigned int hash = ah_table_hash(key, table->size);
  struct ah_t_bucket **bucket = & (table->data[hash]);
  ah_bucket_remove(bucket, key);
}

variable_types: struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; } **


decompiled_code:
__int64 __fastcall ah_table_delete(_QWORD *a1)
{
unsigned int v1; // er12
__int64 v2; // rbx

if ( a1[2] )
{
v1 = 0;
v2 = 0LL;
do
{
ah_bucket_delete(*(_QWORD *)(*a1 + 8 * v2));
*(_QWORD *)(*a1 + 8 * v2) = 0LL;
v2 = ++v1;
}
while ( (unsigned __int64)v1 < a1[2] );
}
ah_free(*a1);
return ah_free(a1);
}

original_code:
void ah_table_delete(ah_table* table)
{
  for(uint i = 0; i < table->size; i++)
  {
    ah_bucket_delete(table->data[i]);
    table->data[i] = ((void *)0);
  }
  ah_free(table->data);
  ah_free(table);
}

canonical_original_code:
void ah_table_delete(struct ah_t_table *table)
{
  for(unsigned int i = 0; i < table->size; i++)
  {
    ah_bucket_delete(table->data[i]);
    table->data[i] = ((void *)0);
  }
  ah_free(table->data);
  ah_free(table);
}

variable_types:
i
unsigned int

user_defined_types: struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; }


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

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

original_code:
ah_bucket* ah_bucket_create_empty()
{
  return ((void *)0);
}

canonical_original_code:
struct ah_t_bucket *ah_bucket_create_empty()
{
  return ((void *)0);
}

return_type: struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; } *


decompiled_code:
__int64 ah_bucket_create()
{
__int64 result; // rax

result = ah_malloc(24LL);
*(_QWORD *)(result + 16) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax

result = func24(24LL);
*(_QWORD *)(result + 16) = 0LL;
return result;
}

original_code:
ah_bucket* ah_bucket_create()
{
  ah_bucket* bucket = (ah_bucket*) ah_malloc(sizeof(ah_bucket));
  bucket->next = ((void *)0);
  return bucket;
}

canonical_original_code:
struct ah_t_bucket *ah_bucket_create()
{
  struct ah_t_bucket *bucket = (ah_bucket*) ah_malloc(sizeof(ah_bucket));
  bucket->next = ((void *)0);
  return bucket;
}


decompiled_code:
__int64 __fastcall ah_bucket_search(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = a1;
if ( a1 && strcmp(*(const char **)a1, a2) )
v2 = ah_bucket_search(*(_QWORD *)(a1 + 16), a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char *a2)
{
__int64 v2; // rbx

v2 = a1;
if ( a1 && strcmp(*(const char **)a1, a2) )
v2 = func15(*(_QWORD *)(a1 + 16), a2);
return v2;
}

original_code:
ah_bucket* ah_bucket_search(ah_bucket* bucket, char* key)
{
  if(((void *)0) == bucket) {
    return ((void *)0);
  }
  if(strcmp(bucket->key, key) == 0) {
    return bucket;
  } else {
    return ah_bucket_search(bucket->next, key);
  }
}

canonical_original_code:
struct ah_t_bucket *ah_bucket_search(struct ah_t_bucket *bucket, char *key)
{
  if(((void *)0) == bucket) {
    return ((void *)0);
  }
  if(strcmp(bucket->key, key) == 0) {
    return bucket;
  } else {
    return ah_bucket_search(bucket->next, key);
  }
}

variable_types:
bucket
struct ah_t_bucket *


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

result = a2;
if ( a1 )
result = ah_bucket_length_acc(*(_QWORD *)(a1 + 16), a2 + 1);
return result;
}

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

result = a2;
if ( a1 )
result = func16(*(_QWORD *)(a1 + 16), a2 + 1);
return result;
}

original_code:
uint ah_bucket_length_acc(ah_bucket* bucket, uint acc)
{
  if(((void *)0) == bucket) {
    return acc;
  } else {
    return ah_bucket_length_acc(bucket->next, acc + 1);
  }
}

canonical_original_code:
unsigned int ah_bucket_length_acc(struct ah_t_bucket *bucket, unsigned int acc)
{
  if(((void *)0) == bucket) {
    return acc;
  } else {
    return ah_bucket_length_acc(bucket->next, acc + 1);
  }
}

variable_types:
acc
unsigned int


decompiled_code:
__int64 __fastcall ah_bucket_length(__int64 a1)
{
return ah_bucket_length_acc(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func16(a1, 0);
}

original_code:
uint ah_bucket_length(ah_bucket* bucket)
{
  return ah_bucket_length_acc(bucket, 0);
}

canonical_original_code:
unsigned int ah_bucket_length(struct ah_t_bucket *bucket)
{
  return ah_bucket_length_acc(bucket, 0);
}


decompiled_code:
int __fastcall ah_bucket_print(__int64 a1)
{
if ( !a1 )
return putchar(10);
printf(" %s ", *(const char **)a1);
return ah_bucket_print(*(_QWORD *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1)
{
if ( !a1 )
return putchar(10);
printf(" %s ", *(const char **)a1);
return func18(*(_QWORD *)(a1 + 16));
}

original_code:
void ah_bucket_print(ah_bucket* bucket)
{
  if(((void *)0) == bucket) {
    printf("\n");
    return;
  }
  printf(" %s ", bucket->key);
  ah_bucket_print(bucket->next);
}

canonical_original_code:
void ah_bucket_print(struct ah_t_bucket *bucket)
{
  if(((void *)0) == bucket) {
    printf("\n");
    return;
  }
  printf(" %s ", bucket->key);
  ah_bucket_print(bucket->next);
}


decompiled_code:
__int64 __fastcall ah_bucket_free(__int64 a1)
{
ah_free(*(_QWORD *)(a1 + 8));
return ah_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
func25(*(_QWORD *)(a1 + 8));
return func25(a1);
}

original_code:
void ah_bucket_free(ah_bucket* bucket)
{
  ah_free(bucket->value);
  ah_free(bucket);
}

canonical_original_code:
void ah_bucket_free(struct ah_t_bucket *bucket)
{
  ah_free(bucket->value);
  ah_free(bucket);
}


decompiled_code:
void __fastcall ah_bucket_remove_acc(__int64 a1, _QWORD *a2, const char *a3)
{
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v4[0] = a1;
if ( a1 )
{
if ( !strcmp(*(const char **)a1, a3) )
{
*a2 = *(_QWORD *)(a1 + 16);
ah_bucket_free(a1);
}
else
{
ah_bucket_remove_acc(*(_QWORD *)(a1 + 16), v4, a3);
}
}
}

original_code:
void ah_bucket_remove_acc(ah_bucket* bucket, ah_bucket** prev, char* key)
{
  if(((void *)0) == bucket) {
    return;
  }
  if(strcmp(bucket->key, key) == 0) {
    *prev = bucket->next;
    ah_bucket_free(bucket);
    return;
  }
  ah_bucket_remove_acc(bucket->next, &bucket, key);
}

canonical_original_code:
void ah_bucket_remove_acc(struct ah_t_bucket *bucket, struct ah_t_bucket **prev, char *key)
{
  if(((void *)0) == bucket) {
    return;
  }
  if(strcmp(bucket->key, key) == 0) {
    *prev = bucket->next;
    ah_bucket_free(bucket);
    return;
  }
  ah_bucket_remove_acc(bucket->next, &bucket, key);
}

variable_types:
prev
struct ah_t_bucket **


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

v2 = *a1;
if ( *a1 && (v3 = *(_QWORD *)(v2 + 16)) != 0 && !strcmp(*(const char **)v2, a2) )
{
*a1 = v3;
ah_bucket_free(v2);
}
else
{
ah_bucket_remove_acc(v2, a1, a2);
}
}

original_code:
void ah_bucket_remove_i(ah_bucket** bucket, char* key)
{
  if(*bucket != ((void *)0) && (*bucket)->next != ((void *)0) && strcmp((*bucket)->key, key) == 0) {
    ah_bucket* tmp = *bucket;
    *bucket = tmp->next;
    ah_bucket_free(tmp);
  } else {
    ah_bucket_remove_acc(*bucket, bucket, key);
  }
}

canonical_original_code:
void ah_bucket_remove_i(struct ah_t_bucket **bucket, char *key)
{
  if(*bucket != ((void *)0) && (*bucket)->next != ((void *)0) && strcmp((*bucket)->key, key) == 0) {
    struct ah_t_bucket *tmp = *bucket;
    *bucket = tmp->next;
    ah_bucket_free(tmp);
  } else {
    ah_bucket_remove_acc(*bucket, bucket, key);
  }
}


decompiled_code:
void __fastcall ah_bucket_remove(__int64 *a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

v2 = *a1;
if ( *a1 )
{
if ( !strcmp(*(const char **)v2, a2) )
{
*a1 = *(_QWORD *)(v2 + 16);
ah_bucket_free(v2);
}
else
{
v3 = *(_QWORD *)(v2 + 16);
if ( v3 )
{
while ( strcmp(*(const char **)v3, a2) )
{
v2 = v3;
if ( !*(_QWORD *)(v3 + 16) )
return;
v3 = *(_QWORD *)(v3 + 16);
}
*(_QWORD *)(v2 + 16) = *(_QWORD *)(v3 + 16);
ah_bucket_free(v3);
}
}
}
}

original_code:
void ah_bucket_remove(ah_bucket** bucket, char* key)
{
  ah_bucket* tgt = *bucket;
  ah_bucket* prev;
  if(((void *)0) == *bucket) return;
  if(strcmp(tgt->key, key) == 0) {
    *bucket = tgt->next;
    ah_bucket_free(tgt);
  } else {
    prev = tgt;
    tgt = tgt->next;
    while(((void *)0) != tgt)
    {
      if(strcmp(tgt->key, key) == 0) {
        prev->next = tgt->next;
        ah_bucket_free(tgt);
        return;
      }
      prev = tgt;
      tgt = tgt->next;
    }
  }
}

canonical_original_code:
void ah_bucket_remove(struct ah_t_bucket **bucket, char *key)
{
  struct ah_t_bucket *tgt = *bucket;
  struct ah_t_bucket *prev;
  if(((void *)0) == *bucket) return;
  if(strcmp(tgt->key, key) == 0) {
    *bucket = tgt->next;
    ah_bucket_free(tgt);
  } else {
    prev = tgt;
    tgt = tgt->next;
    while(((void *)0) != tgt)
    {
      if(strcmp(tgt->key, key) == 0) {
        prev->next = tgt->next;
        ah_bucket_free(tgt);
        return;
      }
      prev = tgt;
      tgt = tgt->next;
    }
  }
}


decompiled_code:
__int64 __fastcall ah_bucket_delete(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 16);
ah_bucket_free(a1);
result = ah_bucket_delete(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 16);
func19(a1);
result = func23(v1);
}
return result;
}

original_code:
void ah_bucket_delete(ah_bucket* bucket)
{
  if(bucket == ((void *)0)) return;
  ah_bucket* next = bucket->next;
  ah_bucket_free(bucket);
  ah_bucket_delete(next);
}

canonical_original_code:
void ah_bucket_delete(struct ah_t_bucket *bucket)
{
  if(bucket == ((void *)0)) return;
  struct ah_t_bucket *next = bucket->next;
  ah_bucket_free(bucket);
  ah_bucket_delete(next);
}


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

result = malloc(a1);
if ( !result )
{
fwrite("Memory allocation error.\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

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

result = malloc(a1);
if ( !result )
{
fwrite("Memory allocation error.\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

original_code:
void* ah_malloc(ulong size)
{
  void* ptr = malloc(size);
  if(!ptr){
    fprintf(stderr, "Memory allocation error.\n");
    exit(1);
  }
  return ptr;
}

canonical_original_code:
void *ah_malloc(unsigned long size)
{
  void *ptr = malloc(size);
  if(!ptr){
    fprintf(stderr, "Memory allocation error.\n");
    exit(1);
  }
  return ptr;
}


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

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

original_code:
void ah_free(void* ptr)
{
  if(ptr) {
    free(ptr);
  }
}

canonical_original_code:
void ah_free(void *ptr)
{
  if(ptr) {
    free(ptr);
  }
}


decompiled_code:
int __fastcall gen_random_key(char *a1, unsigned int a2, unsigned int a3)
{
void *v3; // rsp
unsigned int v4; // er15
char *v5; // rbx
char *v6; // r12
char v8[8]; // [rsp+0h] [rbp-40h] BYREF
char *s; // [rsp+8h] [rbp-38h]

s = a1;
v3 = alloca(16 * (((unsigned __int64)a3 + 15) >> 4));
v4 = a3 - 8;
if ( a3 != 8 )
{
v5 = v8;
v6 = &v8[a3 - 8];
do
*v5++ = rand() % 26 + 97;
while ( v5 != v6 );
}
v8[v4] = 0;
return sprintf(s, "%s%d", v8, a2);
}

canonical_decompiled_code:
int __fastcall func26(char *a1, unsigned int a2, unsigned int a3)
{
void *v3; // rsp
unsigned int v4; // er15
char *v5; // rbx
char *v6; // r12
char v8[8]; // [rsp+0h] [rbp-40h] BYREF
char *s; // [rsp+8h] [rbp-38h]

s = a1;
v3 = alloca(16 * (((unsigned __int64)a3 + 15) >> 4));
v4 = a3 - 8;
if ( a3 != 8 )
{
v5 = v8;
v6 = &v8[a3 - 8];
do
*v5++ = rand() % 26 + 97;
while ( v5 != v6 );
}
v8[v4] = 0;
return sprintf(s, "%s%d", v8, a2);
}

original_code:
void gen_random_key(char* dst, uint k, uint len)
{
  char buff[len];
  uint i;
  for(i = 0; i < len-8; i++) {
    char c = (rand() % 26) + 97;
    buff[i] = c;
  }
  buff[i] = '\0';
  sprintf(dst, "%s%d", buff, k);
}

canonical_original_code:
void gen_random_key(char *dst, unsigned int k, unsigned int len)
{
  char buff[-1];
  unsigned int i;
  for(i = 0; i < len-8; i++) {
    char c = (rand() % 26) + 97;
    buff[i] = c;
  }
  buff[i] = '\0';
  sprintf(dst, "%s%d", buff, k);
}

variable_types:
dst
char *

variable_types:
k
unsigned int

variable_types:
len
unsigned int

variable_types:
buff
char [-1]

variable_types: c char


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
__int64 i; // rbx
int v5; // eax
int v6; // er13
__int64 v7; // rbx
const char *v8; // rax
char v10[112]; // [rsp+0h] [rbp-B8h] BYREF
char src[72]; // [rsp+70h] [rbp-48h] BYREF

v3 = ah_table_create(2000LL);
for ( i = 0LL; i != 1000; ++i )
{
v5 = rand();
gen_random_key(src, i, v5 % 12 + 8);
sprintf(v10, "%d", (unsigned int)i);
strcpy(&data[20 * i], src);
ah_table_set(v3, src, (__int64)v10);
}
v6 = 10;
do
{
v7 = 0LL;
while ( 1 )
{
v8 = (const char *)ah_table_get(v3, &data[20 * v7]);
if ( atoi(v8) != (_DWORD)v7 )
break;
if ( ++v7 == 1000 )
goto LABEL_5;
}
puts("value is changed!!");
LABEL_5:
--v6;
}
while ( v6 );
ah_table_delete(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbp
__int64 i; // rbx
int v5; // eax
int v6; // er13
__int64 v7; // rbx
const char *v8; // rax
char v10[112]; // [rsp+0h] [rbp-B8h] BYREF
char src[72]; // [rsp+70h] [rbp-48h] BYREF

v3 = ah_table_create(2000LL);
for ( i = 0LL; i != 1000; ++i )
{
v5 = rand();
func26(src, i, v5 % 12 + 8);
sprintf(v10, "%d", (unsigned int)i);
strcpy(&data[20 * i], src);
func8(v3, src, (__int64)v10);
}
v6 = 10;
do
{
v7 = 0LL;
while ( 1 )
{
v8 = (const char *)func9(v3, &data[20 * v7]);
if ( atoi(v8) != (_DWORD)v7 )
break;
if ( ++v7 == 1000 )
goto LABEL_5;
}
puts("value is changed!!");
LABEL_5:
--v6;
}
while ( v6 );
func11(v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  ah_table* table = ah_table_create(2000);
  char keybuff[20], valuebuff[100];
  for(uint i = 0; i < 1000; i++) {
    uint len = rand() % (20 - 8) + 8;
    gen_random_key(keybuff, i, len);
    sprintf(valuebuff, "%d", i);
    strcpy(data[i], keybuff);
    ah_table_set(table, keybuff, valuebuff);
  }
  for(uint k = 0; k < 10; k++) {
    for(uint i = 0; i < 1000; i++) {
      char* value = ah_table_get(table, data[i]);
      if(atoi(value) != i) {
        printf("value is changed!!\n");
        break;
      }
    }
  }
  ah_table_delete(table);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  struct ah_t_table *table = ah_table_create(2000);
  char keybuff[20]; char valuebuff[100];
  for(unsigned int i = 0; i < 1000; i++) {
    unsigned int len = rand() % (20 - 8) + 8;
    gen_random_key(keybuff, i, len);
    sprintf(valuebuff, "%d", i);
    strcpy(data[i], keybuff);
    ah_table_set(table, keybuff, valuebuff);
  }
  for(unsigned int k = 0; k < 10; k++) {
    for(unsigned int i = 0; i < 1000; i++) {
      char *value = ah_table_get(table, data[i]);
      if(atoi(value) != i) {
        printf("value is changed!!\n");
        break;
      }
    }
  }
  ah_table_delete(table);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
keybuff
char [20]

variable_types:
valuebuff
char [100]


onDisplay

repo: rnentjes/OpenGL

decompiled_code:
__int64 onDisplay()
{
float v0; // xmm3_4
int i; // ebx
float v2; // xmm4_4
unsigned int v3; // xmm3_4
double v4; // r12
double v5; // rbp
__m128i v6; // xmm5
unsigned int v7; // er14
__m128i v8; // xmm6
__m128i v9; // xmm1
double v10; // xmm7_8
__m128i v11; // xmm3
unsigned int v12; // ebx
__m128i v13; // xmm3
float v15; // [rsp+4h] [rbp-54h]
double cosx; // [rsp+10h] [rbp-48h] BYREF
double sinx[8]; // [rsp+18h] [rbp-40h] BYREF

glClear(0x4000LL);
_glewUseProgram((unsigned int)program);
_glewActiveTexture(33984LL);
glBindTexture(3553LL, (unsigned int)texture_id);
_glewActiveTexture(33985LL);
glBindTexture(3553LL, (unsigned int)texture_id2);
_glewActiveTexture(33986LL);
glBindTexture(3553LL, (unsigned int)texture_id3);
v0 = (double)(int)(glutGet(700LL) - program_start) / 1000.0;
v15 = v0;
_glewBindBuffer(34962LL, (unsigned int)vbo_quad);
_glewVertexAttribPointer((unsigned int)attribute_coord2d, 2LL, 5126LL, 0LL, 0LL, 0LL);
_glewEnableVertexAttribArray((unsigned int)attribute_coord2d);
_glewBindBuffer(34963LL, (unsigned int)vbo_quad_elements);
for ( i = 100; i != 500; ++i )
{
v2 = v15 * 0.999;
v15 = v2;
*(float *)&v3 = (double)i / 1000.0 + (double)i / 1000.0;
sincos(v2, sinx, &cosx);
v4 = cosx;
v5 = sinx[0];
v6 = 0LL;
*(float *)v6.m128i_i32 = cosx * *(float *)&v3;
v7 = _mm_cvtsi128_si32(v6);
v8 = 0LL;
*(float *)v8.m128i_i32 = sinx[0] * *(float *)&v3;
_glewUniform2f((unsigned int)uniform_location, *(double *)v8.m128i_i64, *(double *)v6.m128i_i64);
_glewUniform2f((unsigned int)uniform_size, COERCE_DOUBLE((unsigned __int64)v3), COERCE_DOUBLE((unsigned __int64)v3));
_glewUniform1i((unsigned int)uniform_mytexture, (unsigned int)(i % 3));
glDrawElements(5LL, 4LL, 5123LL, 0LL);
v9 = 0LL;
*(float *)v9.m128i_i32 = COERCE_DOUBLE(*(_QWORD *)&v4 ^ LC2) * *(float *)&v3;
HIDWORD(v10) = 0;
*(float *)&v10 = COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC2) * *(float *)&v3;
_glewUniform2f((unsigned int)uniform_location, v10, *(double *)v9.m128i_i64);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LODWORD(v10)),
*(double *)_mm_cvtsi32_si128(v7).m128i_i64);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v8)).m128i_i64,
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v9)).m128i_i64);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
}
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC3));
v11 = 0LL;
*(float *)v11.m128i_i32 = v5 + v5;
v12 = _mm_cvtsi128_si32(v11);
_glewUniform2f((unsigned int)uniform_size, *(double *)v11.m128i_i64, *(double *)v11.m128i_i64);
_glewUniform1i((unsigned int)uniform_mytexture, 0LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f((unsigned int)uniform_location, COERCE_DOUBLE((unsigned __int64)LC3), 0.0);
v13 = 0LL;
*(float *)v13.m128i_i32 = v4 + v4;
_glewUniform2f((unsigned int)uniform_size, *(double *)v13.m128i_i64, *(double *)v13.m128i_i64);
_glewUniform1i((unsigned int)uniform_mytexture, 1LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC5));
_glewUniform2f(
(unsigned int)uniform_size,
*(double *)_mm_cvtsi32_si128(v12).m128i_i64,
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v13)).m128i_i64);
_glewUniform1i((unsigned int)uniform_mytexture, 2LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewDisableVertexAttribArray((unsigned int)attribute_coord2d);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func0()
{
float v0; // xmm3_4
int i; // ebx
float v2; // xmm4_4
unsigned int v3; // xmm3_4
double v4; // r12
double v5; // rbp
__m128i v6; // xmm5
unsigned int v7; // er14
__m128i v8; // xmm6
__m128i v9; // xmm1
double v10; // xmm7_8
__m128i v11; // xmm3
unsigned int v12; // ebx
__m128i v13; // xmm3
float v15; // [rsp+4h] [rbp-54h]
double cosx; // [rsp+10h] [rbp-48h] BYREF
double sinx[8]; // [rsp+18h] [rbp-40h] BYREF

glClear(0x4000LL);
_glewUseProgram((unsigned int)program);
_glewActiveTexture(33984LL);
glBindTexture(3553LL, (unsigned int)texture_id);
_glewActiveTexture(33985LL);
glBindTexture(3553LL, (unsigned int)texture_id2);
_glewActiveTexture(33986LL);
glBindTexture(3553LL, (unsigned int)texture_id3);
v0 = (double)(int)(glutGet(700LL) - program_start) / 1000.0;
v15 = v0;
_glewBindBuffer(34962LL, (unsigned int)vbo_quad);
_glewVertexAttribPointer((unsigned int)attribute_coord2d, 2LL, 5126LL, 0LL, 0LL, 0LL);
_glewEnableVertexAttribArray((unsigned int)attribute_coord2d);
_glewBindBuffer(34963LL, (unsigned int)vbo_quad_elements);
for ( i = 100; i != 500; ++i )
{
v2 = v15 * 0.999;
v15 = v2;
*(float *)&v3 = (double)i / 1000.0 + (double)i / 1000.0;
sincos(v2, sinx, &cosx);
v4 = cosx;
v5 = sinx[0];
v6 = 0LL;
*(float *)v6.m128i_i32 = cosx * *(float *)&v3;
v7 = _mm_cvtsi128_si32(v6);
v8 = 0LL;
*(float *)v8.m128i_i32 = sinx[0] * *(float *)&v3;
_glewUniform2f((unsigned int)uniform_location, *(double *)v8.m128i_i64, *(double *)v6.m128i_i64);
_glewUniform2f((unsigned int)uniform_size, COERCE_DOUBLE((unsigned __int64)v3), COERCE_DOUBLE((unsigned __int64)v3));
_glewUniform1i((unsigned int)uniform_mytexture, (unsigned int)(i % 3));
glDrawElements(5LL, 4LL, 5123LL, 0LL);
v9 = 0LL;
*(float *)v9.m128i_i32 = COERCE_DOUBLE(*(_QWORD *)&v4 ^ LC2) * *(float *)&v3;
HIDWORD(v10) = 0;
*(float *)&v10 = COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC2) * *(float *)&v3;
_glewUniform2f((unsigned int)uniform_location, v10, *(double *)v9.m128i_i64);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LODWORD(v10)),
*(double *)_mm_cvtsi32_si128(v7).m128i_i64);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v8)).m128i_i64,
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v9)).m128i_i64);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
}
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC3));
v11 = 0LL;
*(float *)v11.m128i_i32 = v5 + v5;
v12 = _mm_cvtsi128_si32(v11);
_glewUniform2f((unsigned int)uniform_size, *(double *)v11.m128i_i64, *(double *)v11.m128i_i64);
_glewUniform1i((unsigned int)uniform_mytexture, 0LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f((unsigned int)uniform_location, COERCE_DOUBLE((unsigned __int64)LC3), 0.0);
v13 = 0LL;
*(float *)v13.m128i_i32 = v4 + v4;
_glewUniform2f((unsigned int)uniform_size, *(double *)v13.m128i_i64, *(double *)v13.m128i_i64);
_glewUniform1i((unsigned int)uniform_mytexture, 1LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC5));
_glewUniform2f(
(unsigned int)uniform_size,
*(double *)_mm_cvtsi32_si128(v12).m128i_i64,
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v13)).m128i_i64);
_glewUniform1i((unsigned int)uniform_mytexture, 2LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewDisableVertexAttribArray((unsigned int)attribute_coord2d);
return glutSwapBuffers();
}

original_code:
void onDisplay() {
    glClear(0x00004000);
    __glewUseProgram(program);
    __glewActiveTexture(0x84C0);
    glBindTexture(0x0DE1, texture_id);
    __glewActiveTexture(0x84C1);
    glBindTexture(0x0DE1, texture_id2);
    __glewActiveTexture(0x84C2);
    glBindTexture(0x0DE1, texture_id3);
    GLfloat r = (glutGet(0x02BC) - program_start) / 1000.0;
    __glewBindBuffer(0x8892, vbo_quad);
    __glewVertexAttribPointer(
            attribute_coord2d,
            2,
            0x1406,
            0,
            0,
            0
            );
    __glewEnableVertexAttribArray(attribute_coord2d);
    __glewBindBuffer(0x8893, vbo_quad_elements);
    int i = 100;
    for (; i < 500; i++) {
      r = r * 0.999;
      GLfloat factor = (i/1000.0)*2.0;
      __glewUniform2f(uniform_location, sin(r) * factor, cos(r) * factor);
      __glewUniform2f(uniform_size, factor, factor);
      __glewUniform1i(uniform_mytexture, i % 3);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
    }
    __glewUniform2f(uniform_location, -0.5, -0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, sin(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 0);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.0);
    __glewUniform2f(uniform_size, cos(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 1);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 2);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewDisableVertexAttribArray(attribute_coord2d);
    glutSwapBuffers();
}

canonical_original_code:
void onDisplay() {
    glClear(0x00004000);
    __glewUseProgram(program);
    __glewActiveTexture(0x84C0);
    glBindTexture(0x0DE1, texture_id);
    __glewActiveTexture(0x84C1);
    glBindTexture(0x0DE1, texture_id2);
    __glewActiveTexture(0x84C2);
    glBindTexture(0x0DE1, texture_id3);
    float r = (glutGet(0x02BC) - program_start) / 1000.0;
    __glewBindBuffer(0x8892, vbo_quad);
    __glewVertexAttribPointer(
            attribute_coord2d,
            2,
            0x1406,
            0,
            0,
            0
            );
    __glewEnableVertexAttribArray(attribute_coord2d);
    __glewBindBuffer(0x8893, vbo_quad_elements);
    int i = 100;
    for (; i < 500; i++) {
      r = r * 0.999;
      float factor = (i/1000.0)*2.0;
      __glewUniform2f(uniform_location, sin(r) * factor, cos(r) * factor);
      __glewUniform2f(uniform_size, factor, factor);
      __glewUniform1i(uniform_mytexture, i % 3);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
    }
    __glewUniform2f(uniform_location, -0.5, -0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, sin(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 0);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.0);
    __glewUniform2f(uniform_size, cos(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 1);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 2);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewDisableVertexAttribArray(attribute_coord2d);
    glutSwapBuffers();
}

variable_types: r float

variable_types: i int

variable_types: factor float


idle

decompiled_code:
__int64 idle()
{
int v0; // eax

++fps_frames;
v0 = glutGet(700LL) - fps_start;
if ( v0 > 1000 )
{
fprintf(stdout, "FPS: %f\n", (double)fps_frames * 1000.0 / (double)v0);
fps_frames = 0;
fps_start += 1000;
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax

++fps_frames;
v0 = glutGet(700LL) - fps_start;
if ( v0 > 1000 )
{
fprintf(stdout, "FPS: %f\n", (double)fps_frames * 1000.0 / (double)v0);
fps_frames = 0;
fps_start += 1000;
}
return glutPostRedisplay();
}

original_code:
void idle() {
    fps_frames++;
    int delta_t = glutGet(0x02BC) - fps_start;
    if (delta_t > 1000) {
        fprintf(stdout, "FPS: %f\n", (1000.0 * fps_frames / delta_t));
        fps_frames = 0;
        fps_start = fps_start + 1000;
    }
    glutPostRedisplay();
}