/* @004d88c0 file=? name=FUN_004d88c0 */

char * __cdecl FUN_004d88c0(char *param_1,int param_2)

{
  char *pcVar1;
  char *pcVar2;
  uint uVar3;
  char *pcVar4;
  char *pcVar5;
  
  pcVar1 = param_1 + param_2;
  pcVar4 = param_1;
  pcVar5 = param_1;
  while( true ) {
    pcVar2 = FUN_004d48f8(pcVar4,'\r',(int)pcVar1 - (int)pcVar4);
    if (pcVar2 == (char *)0x0) {
      pcVar2 = pcVar1;
    }
    uVar3 = (int)pcVar2 - (int)pcVar4;
    if (pcVar5 != pcVar4) {
      FUN_004d4918((undefined4 *)pcVar5,(undefined4 *)pcVar4,uVar3);
    }
    if (pcVar1 + -1 <= pcVar2) break;
    pcVar4 = pcVar2 + 1;
    pcVar5 = pcVar5 + uVar3;
  }
  return pcVar5 + (uVar3 - (int)param_1);
}



/* @004d892c file=? name=FUN_004d892c */

char * __cdecl FUN_004d892c(uint param_1,char *param_2,char *param_3)

{
  char *pcVar1;
  uint uVar2;
  DWORD DVar3;
  char *pcVar4;
  DWORD DVar5;
  char *pcVar6;
  
  if (param_1 < DAT_0051fbc0) {
    if (param_3 + 1 < (char *)0x2) {
      pcVar1 = (char *)0x0;
    }
    else if ((*(byte *)((int)&DAT_0051fbc4 + param_1 * 4 + 1) & 0x40) == 0) {
      pcVar1 = (char *)FUN_004d91c0(param_1,param_2,(DWORD)param_3);
    }
    else if ((*(byte *)((int)&DAT_0051fbc4 + param_1 * 4 + 1) & 2) == 0) {
      pcVar1 = (char *)0x0;
      if (param_3 != (char *)0x0) {
        while( true ) {
          uVar2 = (int)param_3 - (int)pcVar1;
          DVar3 = FUN_004d91c0(param_1,param_2,uVar2);
          if (DVar3 == 0xffffffff) {
            return (char *)0xffffffff;
          }
          if (DVar3 == 0) {
            return pcVar1;
          }
          pcVar4 = FUN_004d48f8(param_2,'\x1a',DVar3);
          if (pcVar4 != (char *)0x0) {
            (&DAT_0051fbc4)[param_1] = (&DAT_0051fbc4)[param_1] | 0x200;
            DVar3 = (int)pcVar4 - (int)param_2;
            if (DVar3 == 0) {
              return pcVar1;
            }
          }
          if ((param_2[DVar3 - 1] == '\r') &&
             (DVar5 = FUN_004d91c0(param_1,param_2 + (DVar3 - 1),1), DVar5 == 0xffffffff)) break;
          pcVar6 = FUN_004d88c0(param_2,DVar3);
          pcVar1 = pcVar1 + (int)pcVar6;
          if ((DVar3 < uVar2) && ((*(byte *)((int)&DAT_0051fbc4 + param_1 * 4 + 1) & 0x20) != 0)) {
            return pcVar1;
          }
          if (pcVar4 != (char *)0x0) {
            return pcVar1;
          }
          if (pcVar6 != (char *)0x0) {
            return pcVar1;
          }
          if (param_3 <= pcVar1) {
            return pcVar1;
          }
        }
        pcVar1 = (char *)0xffffffff;
      }
    }
    else {
      pcVar1 = (char *)0x0;
    }
  }
  else {
    pcVar1 = (char *)FUN_004d9148(-6);
  }
  return pcVar1;
}



/* @004d8a5c file=? name=FUN_004d8a5c */

/* WARNING: Type propagation algorithm not settling */

int __cdecl FUN_004d8a5c(char *param_1,int *param_2,undefined4 *param_3,int param_4)

{
  int iVar1;
  char *pcVar2;
  char *pcVar3;
  char *pcVar4;
  undefined1 *puVar5;
  undefined4 *puVar6;
  char *pcVar7;
  int local_14;
  
  iVar1 = *param_2;
  *param_2 = 0;
  local_14 = 0;
  puVar6 = param_3;
  pcVar7 = param_1;
  while( true ) {
    pcVar4 = param_1 + (iVar1 - (int)pcVar7);
    pcVar2 = FUN_004d48f8(pcVar7,'\n',(int)pcVar4);
    if (pcVar2 != (char *)0x0) {
      pcVar4 = pcVar2 + -(int)pcVar7;
    }
    pcVar3 = (char *)((int)param_3 + (param_4 - (int)puVar6));
    if (pcVar3 < pcVar4) break;
    FUN_004d4918(puVar6,(undefined4 *)pcVar7,(uint)pcVar4);
    puVar5 = (undefined1 *)((int)puVar6 + (int)pcVar4);
    if ((pcVar2 == (char *)0x0) || ((int)param_3 + (param_4 - (int)puVar5) < 2)) {
      *param_2 = (int)(pcVar4 + *param_2);
LAB_004d8b0c:
      return local_14 + (int)pcVar4;
    }
    *puVar5 = 0xd;
    puVar5[1] = 10;
    puVar6 = (undefined4 *)(puVar5 + 2);
    local_14 = local_14 + (int)(pcVar4 + 2);
    pcVar7 = pcVar7 + (int)(pcVar4 + 1);
    *param_2 = (int)(pcVar4 + 1 + *param_2);
  }
  FUN_004d4918(puVar6,(undefined4 *)pcVar7,(uint)pcVar3);
  *param_2 = (int)(pcVar3 + *param_2);
  pcVar4 = pcVar3;
  goto LAB_004d8b0c;
}



/* @004d8b14 file=? name=FUN_004d8b14 */

char * __cdecl FUN_004d8b14(uint param_1,char *param_2,char *param_3)

{
  char *pcVar1;
  char *pcVar2;
  DWORD DVar3;
  undefined4 local_8c [32];
  DWORD local_c;
  char *local_8;
  
  if (param_1 < DAT_0051fbc0) {
    if (param_3 + 1 < (char *)0x2) {
      param_3 = (char *)0x0;
    }
    else {
      if ((*(byte *)((int)&DAT_0051fbc4 + param_1 * 4 + 1) & 8) != 0) {
        FUN_004d9334(param_1,0,2);
      }
      pcVar1 = param_2;
      pcVar2 = param_3;
      if ((*(byte *)((int)&DAT_0051fbc4 + param_1 * 4 + 1) & 0x40) == 0) {
        param_3 = (char *)FUN_004d9224(param_1,param_2,(DWORD)param_3);
      }
      else {
        for (; pcVar2 != (char *)0x0; pcVar2 = pcVar2 + -(int)local_8) {
          local_8 = pcVar2;
          DVar3 = FUN_004d8a5c(pcVar1,(int *)&local_8,local_8c,0x80);
          local_c = FUN_004d9224(param_1,local_8c,DVar3);
          if (DVar3 != local_c) {
            if (local_c == 0xffffffff) {
              return (char *)0xffffffff;
            }
            return pcVar1 + (local_c - (int)param_2);
          }
          pcVar1 = pcVar1 + (int)local_8;
        }
      }
    }
  }
  else {
    param_3 = (char *)FUN_004d9148(-6);
  }
  return param_3;
}



/* @004d8bf4 file=? name=FUN_004d8bf4 */

void __cdecl FUN_004d8bf4(int *param_1)

{
  int iVar1;
  char local_108 [260];
  
  GetCurrentDirectoryA(0x104,local_108);
  if (local_108[0] < 'a') {
    iVar1 = local_108[0] + -0x40;
  }
  else {
    iVar1 = local_108[0] + -0x60;
  }
  *param_1 = iVar1;
  return;
}



/* @004d8c38 file=? name=FUN_004d8c38 */

void __cdecl FUN_004d8c38(char param_1,int *param_2)

{
  DWORD DVar1;
  BOOL BVar2;
  UINT UVar3;
  CHAR local_10c [260];
  CHAR local_8;
  char local_7;
  undefined1 local_6;
  undefined1 local_5;
  
  *param_2 = 0;
  local_8 = '=';
  local_7 = param_1 + '@';
  local_6 = 0x3a;
  local_5 = 0;
  DVar1 = GetEnvironmentVariableA(&local_8,local_10c,0x104);
  if (DVar1 == 0) {
    local_10c[0] = local_7;
    local_10c[1] = 0x3a;
    local_10c[2] = 0x5c;
    local_10c[3] = 0;
    BVar2 = SetEnvironmentVariableA(&local_8,local_10c);
    if (BVar2 != 1) {
      FUN_004d91ac();
      return;
    }
  }
  BVar2 = SetCurrentDirectoryA(local_10c);
  if (BVar2 == 1) {
    builtin_memcpy(local_10c,"A:\\",4);
    for (; local_10c[0] < '['; local_10c[0] = local_10c[0] + '\x01') {
      UVar3 = GetDriveTypeA(local_10c);
      if ((UVar3 != 0) && (UVar3 != 1)) {
        *param_2 = *param_2 + 1;
      }
    }
  }
  else {
    FUN_004d91ac();
  }
  return;
}



/* @004d8ce0 file=? name=FUN_004d8ce0 */

undefined4 __cdecl FUN_004d8ce0(int param_1,int *param_2)

{
  int *piVar1;
  undefined4 uVar2;
  int iVar3;
  
  piVar1 = FUN_004d8d20(param_1,param_2,0x100);
  if (piVar1 == (int *)0x0) {
    uVar2 = 0xffffffff;
  }
  else {
    iVar3 = FUN_004d4a78((char *)((int)param_2 + 3));
    FUN_004d493c(param_2,(undefined4 *)((int)param_2 + 3),iVar3 + 1);
    uVar2 = 0;
  }
  return uVar2;
}



/* @004d8d20 file=? name=FUN_004d8d20 */

int * __cdecl FUN_004d8d20(int param_1,int *param_2,uint param_3)

{
  code *pcVar1;
  DWORD DVar2;
  uint uVar3;
  uint uVar4;
  char cVar5;
  int *piVar6;
  char *pcVar7;
  char *pcVar8;
  int *piVar9;
  bool bVar10;
  char local_10c [260];
  CHAR local_8;
  char local_7;
  undefined1 local_6;
  undefined1 local_5;
  
  if (param_1 == 0) {
    DVar2 = GetCurrentDirectoryA(0x103,local_10c);
    if ((DVar2 == 0) || ((int)param_3 < (int)DVar2)) {
      DAT_00520bcc = 8;
      return (int *)0x0;
    }
  }
  else {
    cVar5 = (char)param_1;
    if (DAT_00525224 == 2) {
      local_10c[0] = cVar5 + '@';
      local_10c[1] = 0x3a;
      local_10c[2] = 0x5c;
      local_10c[3] = 0;
      bVar10 = (char *)0xfffffffc < local_10c;
      pcVar1 = (code *)swi(0x21);
      (*pcVar1)();
      if (bVar10) {
        return (int *)0x0;
      }
    }
    else {
      DVar2 = GetLogicalDrives();
      if ((1 << (cVar5 - 1U & 0x1f) & DVar2) == 0) {
        return (int *)0x0;
      }
      local_8 = '=';
      local_7 = cVar5 + '@';
      local_6 = 0x3a;
      local_5 = 0;
      DVar2 = GetEnvironmentVariableA(&local_8,local_10c,0x103);
      if (DVar2 == 0) {
        local_10c[0] = local_7;
        local_10c[1] = 0x3a;
        local_10c[2] = 0x5c;
        local_10c[3] = 0;
      }
    }
  }
  uVar3 = FUN_004d4a78(local_10c);
  if (uVar3 < param_3) {
    if ((param_2 == (int *)0x0) && (param_2 = FUN_004de55c(param_3), param_2 == (int *)0x0)) {
      DAT_00520bcc = 8;
      param_2 = (int *)0x0;
    }
    else {
      uVar3 = 0xffffffff;
      pcVar7 = local_10c;
      do {
        pcVar8 = pcVar7;
        if (uVar3 == 0) break;
        uVar3 = uVar3 - 1;
        pcVar8 = pcVar7 + 1;
        cVar5 = *pcVar7;
        pcVar7 = pcVar8;
      } while (cVar5 != '\0');
      uVar3 = ~uVar3;
      piVar6 = (int *)(pcVar8 + -uVar3);
      piVar9 = param_2;
      for (uVar4 = uVar3 >> 2; uVar4 != 0; uVar4 = uVar4 - 1) {
        *piVar9 = *piVar6;
        piVar6 = piVar6 + 1;
        piVar9 = piVar9 + 1;
      }
      for (uVar3 = uVar3 & 3; uVar3 != 0; uVar3 = uVar3 - 1) {
        *(char *)piVar9 = (char)*piVar6;
        piVar6 = (int *)((int)piVar6 + 1);
        piVar9 = (int *)((int)piVar9 + 1);
      }
    }
  }
  else {
    DAT_00520bcc = 0x22;
    param_2 = (int *)0x0;
  }
  return param_2;
}



/* @004d8e80 file=? name=FUN_004d8e80 */

int FUN_004d8e80(void)

{
  int local_4;
  
  FUN_004d8bf4(&local_4);
  return local_4 + -1;
}



/* @004d8e90 file=? name=FUN_004d8e90 */

int __cdecl FUN_004d8e90(char param_1)

{
  int local_8;
  
  FUN_004d8c38(param_1 + '\x01',&local_8);
  return local_8;
}



/* @004d8eac file=? name=FUN_004d8eac */

int __cdecl FUN_004d8eac(undefined4 param_1,undefined4 param_2)

{
  int iVar1;
  int *piVar2;
  
  iVar1 = 0;
  for (piVar2 = &DAT_0051fbc4; (iVar1 < DAT_0051fbc0 && (*piVar2 != 0)); piVar2 = piVar2 + 1) {
    iVar1 = iVar1 + 1;
  }
  if (iVar1 == DAT_0051fbc0) {
    return -1;
  }
  (&DAT_0051fbc4)[iVar1] = param_2;
  *(undefined4 *)(&DAT_00524d14 + iVar1 * 4) = param_1;
  return iVar1;
}



/* @004d8eec file=? name=FUN_004d8eec */

uint __cdecl FUN_004d8eec(uint param_1,uint param_2,undefined4 param_3)

{
  int *piVar1;
  
  if (param_2 == 0xffffffff) {
    param_2 = 0;
    for (piVar1 = &DAT_0051fbc4; ((int)param_2 < (int)DAT_0051fbc0 && (*piVar1 != 0));
        piVar1 = piVar1 + 1) {
      param_2 = param_2 + 1;
    }
  }
  if ((param_1 < DAT_0051fbc0) && (param_2 < DAT_0051fbc0)) {
    if (((&DAT_0051fbc4)[param_1] != 0) && ((&DAT_0051fbc4)[param_2] == 0)) {
      (&DAT_0051fbc4)[param_2] = (&DAT_0051fbc4)[param_1];
      *(undefined4 *)(&DAT_00524d14 + param_2 * 4) = param_3;
      return param_2;
    }
    return 0xffffffff;
  }
  return 0xffffffff;
}



/* @004d8f54 file=? name=FUN_004d8f54 */

void __cdecl FUN_004d8f54(uint param_1)

{
  if (param_1 < DAT_0051fbc0) {
    (&DAT_0051fbc4)[param_1] = 0;
  }
  return;
}



/* @004d8f70 file=? name=FUN_004d8f70 */

int __cdecl FUN_004d8f70(int *param_1)

{
  uint uVar1;
  int iVar2;
  byte bVar3;
  int *piVar4;
  uint *puVar5;
  byte *pbVar6;
  int local_8;
  
  iVar2 = DAT_0051fbc0;
  for (piVar4 = &DAT_0051fbc0 + DAT_0051fbc0; (iVar2 != 0 && (*piVar4 == 0)); piVar4 = piVar4 + -1)
  {
    iVar2 = iVar2 + -1;
  }
  if (param_1 == (int *)0x0) {
    if (iVar2 == 0) {
      iVar2 = 0;
    }
    else {
      iVar2 = iVar2 * 5 + 4;
    }
  }
  else {
    *param_1 = iVar2;
    pbVar6 = (byte *)(param_1 + 1);
    local_8 = 0;
    puVar5 = &DAT_0051fbc4;
    if (0 < iVar2) {
      do {
        bVar3 = 1;
        uVar1 = *puVar5;
        if ((uVar1 & 0x800) != 0) {
          bVar3 = 0x21;
        }
        if ((uVar1 & 0x8000) == 0) {
          bVar3 = bVar3 | 0x80;
        }
        if ((uVar1 & 0x2000) != 0) {
          bVar3 = bVar3 | 0x40;
        }
        *pbVar6 = bVar3;
        pbVar6 = pbVar6 + 1;
        local_8 = local_8 + 1;
        puVar5 = puVar5 + 1;
      } while (local_8 < iVar2);
    }
    FUN_004d4918((undefined4 *)pbVar6,(undefined4 *)&DAT_00524d14,iVar2 << 2);
    iVar2 = 0;
  }
  return iVar2;
}



/* @004d9004 file=? name=FUN_004d9004 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void FUN_004d9004(void)

{
  bool bVar1;
  UINT UVar2;
  uint uVar3;
  undefined4 *puVar4;
  undefined3 extraout_var;
  int iVar5;
  uint uVar6;
  uint uVar7;
  uint *puVar8;
  uint *puVar9;
  _STARTUPINFOA local_50;
  
  UVar2 = SetHandleCount(DAT_0051fbc0);
  if (UVar2 < DAT_0051fbc0) {
    DAT_0051fbc0 = UVar2;
  }
  PTR_LAB_005201e0 = FUN_004d8f70;
  bVar1 = false;
  GetStartupInfoA(&local_50);
  if (local_50.cbReserved2 != 0) {
    uVar7 = *(uint *)local_50.lpReserved2;
    puVar8 = (uint *)((int)local_50.lpReserved2 + 4);
    if (uVar7 * 5 + 4 == (uint)local_50.cbReserved2) {
      bVar1 = true;
      iVar5 = 0;
      puVar9 = &DAT_0051fbc4;
      if (0 < (int)uVar7) {
        do {
          uVar6 = *puVar8;
          puVar8 = (uint *)((int)puVar8 + 1);
          uVar3 = 0;
          if ((uVar6 & 0x20) != 0) {
            uVar3 = 0x800;
          }
          if ((uVar6 & 0x40) != 0) {
            uVar3 = uVar3 | 0x2000;
          }
          if ((uVar6 & 0x80) == 0) {
            uVar3 = uVar3 | 0x8000;
          }
          else {
            uVar3 = uVar3 | 0x4000;
          }
          *puVar9 = *puVar9 & 3 | uVar3;
          iVar5 = iVar5 + 1;
          puVar9 = puVar9 + 1;
        } while (iVar5 < (int)uVar7);
      }
      puVar4 = &DAT_0051fbc4 + uVar7;
      for (uVar6 = uVar7; uVar6 < DAT_0051fbc0; uVar6 = uVar6 + 1) {
        *puVar4 = 0;
        puVar4 = puVar4 + 1;
      }
      FUN_004d493c((undefined4 *)&DAT_00524d14,puVar8,uVar7 << 2);
    }
  }
  if (!bVar1) {
    _DAT_00524d14 = GetStdHandle(0xfffffff6);
    DAT_00524d18 = GetStdHandle(0xfffffff5);
    _DAT_00524d1c = GetStdHandle(0xfffffff4);
    uVar7 = 0;
    puVar8 = &DAT_0051fbc4;
    do {
      bVar1 = FUN_004d9304(uVar7);
      if (CONCAT31(extraout_var,bVar1) == 0) {
        *puVar8 = *puVar8 & 0xffffdfff;
      }
      else {
        *puVar8 = *puVar8 | 0x2000;
      }
      uVar7 = uVar7 + 1;
      puVar8 = puVar8 + 1;
    } while ((int)uVar7 < 3);
  }
  return;
}



/* @004d9148 file=? name=FUN_004d9148 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

undefined4 __cdecl FUN_004d9148(int param_1)

{
  if (param_1 < 0) {
    if (-param_1 < DAT_0051fd3c) {
      DAT_00520bcc = -param_1;
      _DAT_00524dd0 = 0xffffffff;
      return 0xffffffff;
    }
  }
  else if (param_1 < 299) goto LAB_004d915e;
  param_1 = 1;
LAB_004d915e:
  _DAT_00524dd0 = param_1;
  DAT_00520bcc = (int)(char)(&DAT_005201e8)[param_1];
  return 0xffffffff;
}



/* @004d91ac file=? name=FUN_004d91ac */

void FUN_004d91ac(void)

{
  DWORD DVar1;
  
  DVar1 = GetLastError();
  FUN_004d9148(DVar1 & 0xffff);
  return;
}



/* @004d91c0 file=? name=FUN_004d91c0 */

DWORD __cdecl FUN_004d91c0(uint param_1,LPVOID param_2,DWORD param_3)

{
  BOOL BVar1;
  DWORD local_8;
  
  if (param_1 < DAT_0051fbc0) {
    BVar1 = ReadFile(*(HANDLE *)(&DAT_00524d14 + param_1 * 4),param_2,param_3,&local_8,
                     (LPOVERLAPPED)0x0);
    if (BVar1 != 1) {
      local_8 = FUN_004d91ac();
    }
  }
  else {
    local_8 = FUN_004d9148(6);
  }
  return local_8;
}



/* @004d9208 file=? name=FUN_004d9208 */

void __cdecl FUN_004d9208(uint param_1,LPVOID param_2,DWORD param_3)

{
  FUN_004d91c0(param_1,param_2,param_3);
  return;
}



/* @004d9224 file=? name=FUN_004d9224 */

DWORD __cdecl FUN_004d9224(uint param_1,LPCVOID param_2,DWORD param_3)

{
  BOOL BVar1;
  DWORD local_8;
  
  if (param_1 < DAT_0051fbc0) {
    BVar1 = WriteFile(*(HANDLE *)(&DAT_00524d14 + param_1 * 4),param_2,param_3,&local_8,
                      (LPOVERLAPPED)0x0);
    if (BVar1 != 1) {
      local_8 = FUN_004d91ac();
    }
  }
  else {
    local_8 = FUN_004d9148(6);
  }
  return local_8;
}



/* @004d926c file=? name=FUN_004d926c */

void __cdecl FUN_004d926c(uint param_1,LPCVOID param_2,DWORD param_3)

{
  FUN_004d9224(param_1,param_2,param_3);
  return;
}



/* @004d9288 file=? name=FUN_004d9288 */

undefined4 __cdecl FUN_004d9288(LPCSTR param_1,byte param_2)

{
  DWORD DVar1;
  undefined4 uVar2;
  
  DVar1 = GetFileAttributesA(param_1);
  if (DVar1 == 0xffffffff) {
    uVar2 = FUN_004d91ac();
    return uVar2;
  }
  if (((param_2 & 2) != 0) && ((DVar1 & 1) != 0)) {
    DAT_00520bcc = 5;
    return 0xffffffff;
  }
  return 0;
}



/* @004d92c4 file=? name=FUN_004d92c4 */

undefined4 __cdecl FUN_004d92c4(uint param_1)

{
  undefined4 uVar1;
  BOOL BVar2;
  
  if (DAT_0051fbc0 <= param_1) {
    uVar1 = FUN_004d9148(6);
    return uVar1;
  }
  BVar2 = CloseHandle(*(HANDLE *)(&DAT_00524d14 + param_1 * 4));
  if (BVar2 == 1) {
    (&DAT_0051fbc4)[param_1] = 0;
    return 0;
  }
  uVar1 = FUN_004d91ac();
  return uVar1;
}



/* @004d9304 file=? name=FUN_004d9304 */

bool __cdecl FUN_004d9304(uint param_1)

{
  DWORD DVar1;
  
  if (DAT_0051fbc0 <= param_1) {
    return false;
  }
  DVar1 = GetFileType(*(HANDLE *)(&DAT_00524d14 + param_1 * 4));
  return DVar1 == 2;
}



/* @004d9334 file=? name=FUN_004d9334 */

DWORD __cdecl FUN_004d9334(uint param_1,LONG param_2,int param_3)

{
  DWORD DVar1;
  
  if (param_1 < DAT_0051fbc0) {
    if (param_3 == 0) {
      DVar1 = 0;
    }
    else if (param_3 == 1) {
      DVar1 = 1;
    }
    else {
      if (param_3 != 2) {
        DVar1 = FUN_004d9148(1);
        return DVar1;
      }
      DVar1 = 2;
    }
    (&DAT_0051fbc4)[param_1] = (&DAT_0051fbc4)[param_1] & 0xfffffdff;
    DVar1 = SetFilePointer(*(HANDLE *)(&DAT_00524d14 + param_1 * 4),param_2,(PLONG)0x0,DVar1);
    if (DVar1 == 0xffffffff) {
      FUN_004d91ac();
    }
  }
  else {
    DVar1 = FUN_004d9148(6);
  }
  return DVar1;
}



/* @004d93ac file=? name=FUN_004d93ac */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

int __cdecl FUN_004d93ac(LPCSTR param_1,uint param_2,uint param_3)

{
  bool bVar1;
  uint uVar2;
  int iVar3;
  HANDLE hObject;
  undefined3 extraout_var;
  DWORD dwFlagsAndAttributes;
  DWORD DVar4;
  _SECURITY_ATTRIBUTES local_18;
  DWORD local_c;
  DWORD local_8;
  
  if ((param_2 & 0xc000) == 0) {
    param_2 = param_2 | *(uint *)PTR_DAT_0051fc68 & 0xc000;
  }
  if ((param_2 & 0x8000) == 0) {
    param_2 = param_2 | 0x4000;
  }
  uVar2 = param_2 & 0x700;
  if (uVar2 < 0x501) {
    if (uVar2 == 0x500) {
LAB_004d940f:
      DVar4 = 1;
      goto LAB_004d9430;
    }
    if (uVar2 == 0x100) {
      DVar4 = 4;
      goto LAB_004d9430;
    }
    if (uVar2 != 0x200) {
      if (uVar2 == 0x300) {
        DVar4 = 2;
        goto LAB_004d9430;
      }
      goto LAB_004d942b;
    }
  }
  else if (uVar2 != 0x600) {
    if (uVar2 != 0x700) {
LAB_004d942b:
      DVar4 = 3;
      goto LAB_004d9430;
    }
    goto LAB_004d940f;
  }
  DVar4 = 5;
LAB_004d9430:
  if ((param_2 & 0x100) == 0) {
    dwFlagsAndAttributes = GetFileAttributesA(param_1);
    if (dwFlagsAndAttributes == 0xffffffff) {
      dwFlagsAndAttributes = 0;
    }
  }
  else if ((param_3 & _DAT_005201e4 & 0x80) == 0) {
    dwFlagsAndAttributes = 1;
  }
  else {
    dwFlagsAndAttributes = 0x80;
  }
  uVar2 = param_2 & 3;
  if (uVar2 == 0) {
    local_8 = 0x80000000;
  }
  else if (uVar2 == 1) {
    local_8 = 0x40000000;
  }
  else {
    if (uVar2 != 2) {
      iVar3 = FUN_004d9148(1);
      return iVar3;
    }
    local_8 = 0xc0000000;
  }
  uVar2 = param_2 & 0x70;
  if (uVar2 == 0x10) {
    local_c = 0;
  }
  else if (uVar2 == 0x20) {
    local_c = 1;
  }
  else if (uVar2 == 0x30) {
    local_c = 2;
  }
  else {
    local_c = 3;
  }
  local_18.nLength = 0xc;
  local_18.lpSecurityDescriptor = (LPVOID)0x0;
  local_18.bInheritHandle = (BOOL)((param_2 & 0x80) == 0);
  hObject = CreateFileA(param_1,local_8,local_c,&local_18,DVar4,dwFlagsAndAttributes,(HANDLE)0x0);
  if (hObject == (HANDLE)0xffffffff) {
    DVar4 = GetLastError();
    uVar2 = DVar4 & 0xffff;
    if ((uVar2 == 0x6e) && (uVar2 = 0x50, (param_2 & 0x100) == 0)) {
      uVar2 = 2;
    }
    iVar3 = FUN_004d9148(uVar2);
  }
  else {
    bVar1 = FUN_004d9304((uint)hObject);
    if (CONCAT31(extraout_var,bVar1) != 0) {
      param_2 = param_2 | 0x2000;
    }
    iVar3 = FUN_004d8eac(hObject,param_2 & 0xfffff8ff);
    if (iVar3 == -1) {
      FUN_004d9148(4);
      CloseHandle(hObject);
    }
  }
  return iVar3;
}



/* @004d959c file=? name=FUN_004d959c */

undefined4 __cdecl FUN_004d959c(LPCSTR param_1)

{
  BOOL BVar1;
  undefined4 uVar2;
  
  BVar1 = DeleteFileA(param_1);
  if (BVar1 == 1) {
    uVar2 = 0;
  }
  else {
    uVar2 = FUN_004d91ac();
  }
  return uVar2;
}



/* @004d9800 file=? name=FUN_004d9800 */

void FUN_004d9800(void)

{
  undefined4 *puVar1;
  int iVar2;
  undefined4 *unaff_FS_OFFSET;
  undefined4 local_30;
  
  FUN_004d66b8();
  puVar1 = DAT_00524ef8;
  if (DAT_00524ef8 != (undefined4 *)0x0) {
    iVar2 = FUN_004d67b0((int)DAT_00524ef8,0);
    *DAT_00524c68 = *DAT_00524c68 + iVar2;
    (**(code **)*puVar1)(puVar1,3);
  }
  puVar1 = DAT_00524efc;
  if (DAT_00524efc != (undefined4 *)0x0) {
    iVar2 = FUN_004d67b0((int)DAT_00524efc,0);
    *DAT_00524c68 = *DAT_00524c68 + iVar2;
    (**(code **)*puVar1)(puVar1,3);
  }
  puVar1 = DAT_00524f00;
  if (DAT_00524f00 != (undefined4 *)0x0) {
    iVar2 = FUN_004d67b0((int)DAT_00524f00,0);
    *DAT_00524c68 = *DAT_00524c68 + iVar2;
    (**(code **)*puVar1)(puVar1,3);
  }
  *unaff_FS_OFFSET = local_30;
  return;
}



/* @004d98e0 file=? name=FUN_004d98e0 */

void FUN_004d98e0(void)

{
  undefined4 *unaff_FS_OFFSET;
  undefined4 local_24;
  
  FUN_004d66b8();
  FUN_004daac0((undefined4 *)&DAT_00524dd4,0);
  FUN_004db534(&DAT_00524e20,0);
  FUN_004db534((undefined4 *)&DAT_00524e68,0);
  FUN_004db534((undefined4 *)&DAT_00524eb0,0);
  *unaff_FS_OFFSET = local_24;
  return;
}



/* @004d9c38 file=? name=FUN_004d9c38 */

int * __cdecl FUN_004d9c38(int *param_1)

{
  FUN_004db92c(param_1,10);
  FUN_004db6b4(param_1);
  return param_1;
}



/* @004d9c58 file=? name=FUN_004d9c58 */

int * __cdecl FUN_004d9c58(int *param_1)

{
  FUN_004db92c(param_1,0);
  return param_1;
}



/* @004d9c70 file=? name=FUN_004d9c70 */

int * __cdecl FUN_004d9c70(int *param_1)

{
  FUN_004db6b4(param_1);
  return param_1;
}



/* @004d9cc4 file=? name=FUN_004d9cc4 */

int * __cdecl FUN_004d9cc4(int *param_1)

{
  bool bVar1;
  int iVar2;
  
  if (param_1[10] == -1) {
    *(undefined2 *)(param_1 + 0xc) = 0;
  }
  if ((short)param_1[0xc] == 0) {
    param_1 = (int *)0x0;
  }
  else {
    bVar1 = false;
    if (param_1[5] == 0) {
      iVar2 = 0;
    }
    else {
      iVar2 = param_1[5] - param_1[4];
    }
    if (iVar2 != 0) {
      bVar1 = true;
      iVar2 = (**(code **)(*param_1 + 0x18))(param_1,0xffffffff);
      if (iVar2 != -1) {
        bVar1 = false;
      }
    }
    iVar2 = thunk_FUN_004d92c4(param_1[10]);
    param_1[10] = -1;
    *(undefined2 *)(param_1 + 0xc) = 0;
    if (bVar1 || iVar2 != 0) {
      param_1 = (int *)0x0;
    }
  }
  return param_1;
}



/* @004d9d34 file=? name=FUN_004d9d34 */

undefined4 * __cdecl FUN_004d9d34(undefined4 *param_1)

{
  uint uVar1;
  uint uVar2;
  
  FUN_004dc35c(param_1);
  *param_1 = &PTR_FUN_0052050c;
  param_1[10] = 0xffffffff;
  param_1[0xb] = 0;
  *(undefined2 *)(param_1 + 0xc) = 0;
  *(undefined4 *)((int)param_1 + 0x32) = 0;
  uVar2 = FUN_004022b0(0x204);
  if (uVar2 != 0) {
    FUN_004dc4fc((int)param_1,uVar2,uVar2 + 0x204,1);
    uVar1 = uVar2 + 4;
    FUN_004dc598((int)param_1,uVar1,uVar1);
    FUN_004dc564((int)param_1,uVar2,uVar1,uVar1);
  }
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004d9e28 file=? name=FUN_004d9e28 */

void __cdecl FUN_004d9e28(int *param_1,byte param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    *param_1 = (int)&PTR_FUN_0052050c;
    if (param_1[0xb] == 0) {
      (**(code **)(*param_1 + 0x18))(param_1,0xffffffff);
    }
    else {
      FUN_004d9cc4(param_1);
    }
    FUN_004dc48c(param_1,0);
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004d9e78 file=? name=FUN_004d9e78 */

undefined4 __thiscall FUN_004d9e78(void *this,int *param_1,uint param_2)

{
  uint uVar1;
  undefined1 *puVar2;
  undefined4 uVar3;
  char *pcVar4;
  int iVar5;
  undefined4 uStack_8;
  
  if (((short)param_1[0xc] == 0) || ((param_1[0xb] & 3U) == 1)) {
    uVar3 = 0xffffffff;
  }
  else {
    if ((*(short *)((int)param_1 + 6) == 0) && (param_1[2] != 0)) {
      uStack_8 = this;
      iVar5 = (**(code **)(*param_1 + 0x24))(param_1);
      if (iVar5 != 0) {
        return 0xffffffff;
      }
      iVar5 = 4;
      if (param_1[3] - param_1[2] < 9) {
        iVar5 = 1;
      }
      uVar1 = param_1[2];
      FUN_004dc598((int)param_1,iVar5 + uVar1,(param_1[3] - uVar1) + uVar1);
      FUN_004dc564((int)param_1,uVar1,iVar5 + uVar1,iVar5 + uVar1);
      if (param_2 != 0xffffffff) {
        if ((uint)param_1[5] < (uint)param_1[6]) {
          puVar2 = (undefined1 *)param_1[5];
          param_1[5] = param_1[5] + 1;
          *puVar2 = (undefined1)param_2;
        }
        else {
          (**(code **)(*param_1 + 0x18))(param_1,param_2 & 0xff);
        }
        param_1[8] = param_1[8] + 1;
      }
    }
    else if (param_2 != 0xffffffff) {
      uStack_8 = (void *)CONCAT13((undefined1)param_2,(int3)this);
      pcVar4 = thunk_FUN_004d8b14(param_1[10],(char *)((int)&uStack_8 + 3),(char *)0x1);
      if (pcVar4 != (char *)0x1) {
        return 0xffffffff;
      }
    }
    uVar3 = 1;
  }
  return uVar3;
}



/* @004d9f60 file=? name=FUN_004d9f60 */

int __cdecl FUN_004d9f60(int param_1,LPCSTR param_2,uint param_3,uint param_4)

{
  uint uVar1;
  uint uVar2;
  int iVar3;
  DWORD DVar4;
  
  if ((*(short *)(param_1 + 0x30) == 0) && (param_3 != 0)) {
    if ((param_3 & 2) == 0) {
      if ((param_3 & 1) == 0) {
        return 0;
      }
      uVar2 = 0;
    }
    else {
      if ((param_3 & 1) == 0) {
        uVar1 = 1;
      }
      else {
        uVar1 = 2;
      }
      uVar2 = uVar1;
      if (((param_3 & 0x20) == 0) && (uVar2 = uVar1 | 0x100, (param_3 & 0x40) != 0)) {
        uVar2 = uVar1 | 0x500;
      }
      if ((param_3 & 0x10) != 0) {
        uVar2 = uVar2 | 0x200;
      }
    }
    if ((param_3 & 0x80) == 0) {
      uVar2 = uVar2 | 0x4000;
    }
    else {
      uVar2 = uVar2 | 0x8000;
    }
    if ((param_3 & 8) != 0) {
      uVar2 = uVar2 | 0x800;
    }
    uVar2 = thunk_FUN_004d93ac(param_2,uVar2,param_4);
    if (uVar2 == 0xffffffff) {
      param_1 = 0;
    }
    else {
      *(uint *)(param_1 + 0x28) = uVar2;
      *(undefined2 *)(param_1 + 0x30) = 1;
      *(uint *)(param_1 + 0x2c) = param_3;
      iVar3 = 2;
      if ((param_3 & 4) == 0) {
        iVar3 = 0;
      }
      DVar4 = thunk_FUN_004d9334(uVar2,0,iVar3);
      *(DWORD *)(param_1 + 0x32) = DVar4;
      if (*(int *)(param_1 + 0x32) == -1) {
        param_1 = 0;
      }
      else {
        uVar2 = *(uint *)(param_1 + 8);
        if (uVar2 == 0) {
          iVar3 = 0;
        }
        else {
          iVar3 = 4;
          if (*(int *)(param_1 + 0xc) - *(int *)(param_1 + 8) < 9) {
            iVar3 = 1;
          }
        }
        FUN_004dc598(param_1,iVar3 + uVar2,iVar3 + uVar2);
        FUN_004dc564(param_1,uVar2,iVar3 + uVar2,iVar3 + uVar2);
      }
    }
  }
  else {
    param_1 = 0;
  }
  return param_1;
}



/* @004da44c file=? name=FUN_004da44c */

void __cdecl FUN_004da44c(int *param_1)

{
  int *piVar1;
  
  piVar1 = FUN_004d9cc4(param_1 + 2);
  if (piVar1 != (int *)0x0) {
    FUN_004dc680(*param_1,0);
    return;
  }
  FUN_004dc80c(*param_1,2);
  return;
}



/* @004da484 file=? name=FUN_004da484 */

int * __cdecl FUN_004da484(int *param_1,short param_2)

{
  if (param_2 == 0) {
    *param_1 = (int)(param_1 + 0x11);
    FUN_004dc6bc(param_1 + 0x11);
  }
  param_1[1] = (int)&PTR_FUN_00520550;
  *(undefined ***)*param_1 = &PTR_LAB_0052055c;
  FUN_004d9d34(param_1 + 2);
  FUN_004dc738(*param_1,param_1 + 2);
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004da538 file=? name=FUN_004da538 */

int * __cdecl FUN_004da538(int *param_1,short param_2,LPCSTR param_3,uint param_4,uint param_5)

{
  if (param_2 == 0) {
    *param_1 = (int)(param_1 + 0x11);
    FUN_004dc6bc(param_1 + 0x11);
  }
  param_1[1] = (int)&PTR_FUN_00520550;
  *(undefined ***)*param_1 = &PTR_LAB_0052055c;
  FUN_004d9d34(param_1 + 2);
  FUN_004dc738(*param_1,param_1 + 2);
  FUN_004da5f8(param_1,param_3,param_4,param_5);
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004da59c file=? name=FUN_004da59c */

void __cdecl FUN_004da59c(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_00520550;
    *(undefined ***)*param_1 = &PTR_LAB_0052055c;
    FUN_004d9e28(param_1 + 2,2);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 0x11,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004da5f8 file=? name=FUN_004da5f8 */

void __cdecl FUN_004da5f8(int *param_1,LPCSTR param_2,uint param_3,uint param_4)

{
  int iVar1;
  
  if ((param_3 & 8) == 0) {
    if ((param_3 & 0xf) == 2) {
      param_3 = param_3 | 0x10;
    }
  }
  else {
    param_3 = param_3 | 2;
  }
  if ((short)param_1[0xe] == 0) {
    iVar1 = FUN_004d9f60((int)(param_1 + 2),param_2,param_3,param_4);
    if (iVar1 == 0) {
      FUN_004dc680(*param_1,4);
    }
    else {
      FUN_004dc680(*param_1,0);
    }
  }
  else {
    FUN_004dc680(*param_1,2);
  }
  return;
}



/* @004da66c file=? name=FUN_004da66c */

int * __cdecl FUN_004da66c(int *param_1,short param_2,LPCSTR param_3,uint param_4,uint param_5)

{
  int *piVar1;
  
  if (param_2 == 0) {
    piVar1 = param_1 + 0x14;
    *param_1 = (int)piVar1;
    param_1[0x11] = (int)piVar1;
    FUN_004dc6bc(piVar1);
  }
  FUN_004da538(param_1,1,param_3,param_4 | 1,param_5);
  FUN_004daa7c(param_1 + 0x11,1);
  param_1[1] = (int)&PTR_FUN_0052056c;
  param_1[0x12] = (int)&PTR_LAB_00520578;
  *(undefined ***)*param_1 = &PTR_LAB_00520584;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004da754 file=? name=FUN_004da754 */

void __cdecl FUN_004da754(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_0052056c;
    param_1[0x12] = (int)&PTR_LAB_00520578;
    *(undefined ***)*param_1 = &PTR_LAB_00520584;
    FUN_004dabf8(param_1 + 0x11,0);
    FUN_004da59c(param_1,0);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 0x14,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004da7c0 file=? name=FUN_004da7c0 */

int * __cdecl FUN_004da7c0(int *param_1,short param_2)

{
  int *piVar1;
  
  if (param_2 == 0) {
    piVar1 = param_1 + 0x16;
    *param_1 = (int)piVar1;
    param_1[0x11] = (int)piVar1;
    param_1[0x14] = (int)piVar1;
    FUN_004dc6bc(piVar1);
  }
  FUN_004da484(param_1,1);
  FUN_004da988(param_1 + 0x11,1);
  param_1[1] = (int)&PTR_FUN_00520594;
  param_1[0x12] = (int)&PTR_LAB_005205a0;
  param_1[0x15] = (int)&PTR_LAB_005205ac;
  *(undefined ***)*param_1 = &PTR_LAB_005205b8;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004da914 file=? name=FUN_004da914 */

void __cdecl FUN_004da914(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_00520594;
    param_1[0x12] = (int)&PTR_LAB_005205a0;
    param_1[0x15] = (int)&PTR_LAB_005205ac;
    *(undefined ***)*param_1 = &PTR_LAB_005205b8;
    FUN_004da9f4(param_1 + 0x11,0);
    FUN_004da59c(param_1,0);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 0x16,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004da988 file=? name=FUN_004da988 */

undefined4 * __cdecl FUN_004da988(undefined4 *param_1,short param_2)

{
  undefined4 *puVar1;
  
  if (param_2 == 0) {
    puVar1 = param_1 + 5;
    *param_1 = puVar1;
    param_1[3] = puVar1;
    FUN_004dc6bc(puVar1);
  }
  FUN_004daa7c(param_1,1);
  FUN_004db4b0(param_1 + 3,1);
  param_1[1] = &PTR_FUN_005205c8;
  param_1[4] = &PTR_LAB_005205d4;
  *(undefined ***)*param_1 = &PTR_LAB_005205e0;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004da9f4 file=? name=FUN_004da9f4 */

void __cdecl FUN_004da9f4(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_005205c8;
    param_1[4] = (int)&PTR_LAB_005205d4;
    *(undefined ***)*param_1 = &PTR_LAB_005205e0;
    FUN_004db580(param_1 + 3,0);
    FUN_004dabf8(param_1,0);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 5,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004daa60 file=? name=FUN_004daa60 */

int * __cdecl FUN_004daa60(int *param_1,undefined4 param_2)

{
  FUN_004dc738(*param_1,param_2);
  return param_1;
}



/* @004daa7c file=? name=FUN_004daa7c */

undefined4 * __cdecl FUN_004daa7c(undefined4 *param_1,short param_2)

{
  if (param_2 == 0) {
    *param_1 = param_1 + 3;
    FUN_004dc6bc(param_1 + 3);
  }
  param_1[1] = &PTR_FUN_005205f0;
  *(undefined ***)*param_1 = &PTR_LAB_005205fc;
  param_1[2] = 0;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004daac0 file=? name=FUN_004daac0 */

undefined4 * __cdecl FUN_004daac0(undefined4 *param_1,short param_2)

{
  if (param_2 == 0) {
    *param_1 = param_1 + 3;
    FUN_004dc6bc(param_1 + 3);
  }
  FUN_004daa7c(param_1,1);
  param_1[1] = &PTR_FUN_0052060c;
  *(undefined ***)*param_1 = &PTR_LAB_00520618;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004dab0c file=? name=FUN_004dab0c */

uint __cdecl FUN_004dab0c(int *param_1)

{
  int *piVar1;
  byte *pbVar2;
  int iVar3;
  uint uVar4;
  
  piVar1 = *(int **)(*param_1 + 4);
  if ((uint)piVar1[9] <= (uint)piVar1[8]) {
    iVar3 = (**(code **)(*piVar1 + 0xc))(piVar1);
    if (iVar3 == -1) {
      uVar4 = 0xffffffff;
      goto LAB_004dab3f;
    }
  }
  pbVar2 = *(byte **)(*(int *)(*param_1 + 4) + 0x20);
  piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x20);
  *piVar1 = *piVar1 + 1;
  uVar4 = (uint)*pbVar2;
LAB_004dab3f:
  if (uVar4 == 0xffffffff) {
    FUN_004dc80c(*param_1,3);
  }
  else {
    param_1[2] = param_1[2] + 1;
  }
  return uVar4;
}



/* @004dab60 file=? name=FUN_004dab60 */

bool __cdecl FUN_004dab60(int *param_1,int param_2)

{
  int iVar1;
  
  param_1[2] = 0;
  if (*(int *)(*param_1 + 0xc) != 0) {
    FUN_004dc80c(*param_1,2);
    return false;
  }
  if (*(int *)(*param_1 + 8) != 0) {
    if (param_2 != 0) {
      if (*(uint *)(*(int *)(*param_1 + 4) + 0x20) < *(uint *)(*(int *)(*param_1 + 4) + 0x24)) {
        iVar1 = *(int *)(*(int *)(*param_1 + 4) + 0x24) - *(int *)(*(int *)(*param_1 + 4) + 0x20);
      }
      else {
        iVar1 = 0;
      }
      if (param_2 <= iVar1) goto LAB_004dabbf;
    }
    FUN_004db6b4(*(int **)(*param_1 + 8));
  }
LAB_004dabbf:
  if ((param_2 == 0) && ((*(byte *)(*param_1 + 0x11) & 1) != 0)) {
    FUN_004dac9c(param_1);
    if (*(int *)(*param_1 + 0xc) != 0) {
      FUN_004dc80c(*param_1,2);
    }
  }
  return *(int *)(*param_1 + 0xc) == 0;
}



/* @004dabf8 file=? name=FUN_004dabf8 */

void __cdecl FUN_004dabf8(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_005205f0;
    *(undefined ***)*param_1 = &PTR_LAB_005205fc;
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 3,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004dac44 file=? name=FUN_004dac44 */

void __cdecl FUN_004dac44(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_0052060c;
    *(undefined ***)*param_1 = &PTR_LAB_00520618;
    FUN_004dabf8(param_1,0);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 3,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004dac9c file=? name=FUN_004dac9c */

void __cdecl FUN_004dac9c(int *param_1)

{
  int *piVar1;
  uint uVar2;
  
  while( true ) {
    if (*(uint *)(*(int *)(*param_1 + 4) + 0x20) < *(uint *)(*(int *)(*param_1 + 4) + 0x24)) {
      uVar2 = (uint)**(byte **)(*(int *)(*param_1 + 4) + 0x20);
    }
    else {
      uVar2 = (**(code **)(**(int **)(*param_1 + 4) + 0xc))(*(undefined4 *)(*param_1 + 4));
    }
    if (((&DAT_005207dd)[uVar2] & 1) == 0) break;
    piVar1 = *(int **)(*param_1 + 4);
    if ((uint)piVar1[8] < (uint)piVar1[9]) {
      piVar1[8] = piVar1[8] + 1;
    }
    else {
      (**(code **)(*piVar1 + 0xc))(piVar1);
    }
    param_1[2] = param_1[2] + 1;
  }
  if (uVar2 == 0xffffffff) {
    FUN_004dc80c(*param_1,1);
  }
  return;
}



/* @004dad10 file=? name=FUN_004dad10 */

int * __cdecl FUN_004dad10(int *param_1,undefined1 *param_2,int param_3,byte param_4)

{
  int *piVar1;
  bool bVar2;
  undefined3 extraout_var;
  uint uVar3;
  undefined1 *puVar4;
  
  bVar2 = FUN_004dab60(param_1,1);
  puVar4 = param_2;
  if (CONCAT31(extraout_var,bVar2) != 0) {
    uVar3 = 0;
    while (param_3 = param_3 + -1, 0 < param_3) {
      if (*(uint *)(*(int *)(*param_1 + 4) + 0x20) < *(uint *)(*(int *)(*param_1 + 4) + 0x24)) {
        uVar3 = (uint)**(byte **)(*(int *)(*param_1 + 4) + 0x20);
      }
      else {
        uVar3 = (**(code **)(**(int **)(*param_1 + 4) + 0xc))(*(undefined4 *)(*param_1 + 4));
      }
      if (uVar3 == 0xffffffff) break;
      param_1[2] = param_1[2] + 1;
      piVar1 = *(int **)(*param_1 + 4);
      if ((uint)piVar1[8] < (uint)piVar1[9]) {
        piVar1[8] = piVar1[8] + 1;
      }
      else {
        (**(code **)(*piVar1 + 0xc))(piVar1);
      }
      if (uVar3 == param_4) break;
      *puVar4 = (char)uVar3;
      puVar4 = puVar4 + 1;
    }
    if (uVar3 == 0xffffffff) {
      uVar3 = 3;
      if (puVar4 != param_2) {
        uVar3 = 1;
      }
      FUN_004dc80c(*param_1,uVar3);
    }
  }
  *puVar4 = 0;
  return param_1;
}



/* @004dadcc file=? name=FUN_004dadcc */

int * __cdecl FUN_004dadcc(int *param_1,undefined1 *param_2)

{
  int *piVar1;
  undefined1 *puVar2;
  bool bVar3;
  undefined1 uVar4;
  undefined3 extraout_var;
  int iVar5;
  uint uVar6;
  
  bVar3 = FUN_004dab60(param_1,1);
  if (CONCAT31(extraout_var,bVar3) == 0) {
    FUN_004dc80c(*param_1,2);
    return param_1;
  }
  if (*(uint *)(*(int *)(*param_1 + 4) + 0x20) < *(uint *)(*(int *)(*param_1 + 4) + 0x24)) {
    iVar5 = *(int *)(*(int *)(*param_1 + 4) + 0x24) - *(int *)(*(int *)(*param_1 + 4) + 0x20);
  }
  else {
    iVar5 = 0;
  }
  if (iVar5 != 0) {
    param_1[2] = 1;
    piVar1 = *(int **)(*param_1 + 4);
    if (((uint)piVar1[8] < (uint)piVar1[9]) ||
       (iVar5 = (**(code **)(*piVar1 + 0xc))(piVar1), iVar5 != -1)) {
      puVar2 = *(undefined1 **)(*(int *)(*param_1 + 4) + 0x20);
      piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x20);
      *piVar1 = *piVar1 + 1;
      uVar4 = *puVar2;
    }
    else {
      uVar4 = 0xff;
    }
    *param_2 = uVar4;
    return param_1;
  }
  uVar6 = FUN_004dab0c(param_1);
  *param_2 = (char)uVar6;
  return param_1;
}



/* @004dae60 file=? name=FUN_004dae60 */

int * __cdecl FUN_004dae60(int *param_1,undefined1 *param_2,int param_3)

{
  int *piVar1;
  bool bVar2;
  undefined3 extraout_var;
  uint uVar3;
  
  bVar2 = FUN_004dab60(param_1,1);
  if (CONCAT31(extraout_var,bVar2) != 0) {
    uVar3 = 0;
    while( true ) {
      param_3 = param_3 + -1;
      if (param_3 < 0) break;
      if (*(uint *)(*(int *)(*param_1 + 4) + 0x20) < *(uint *)(*(int *)(*param_1 + 4) + 0x24)) {
        uVar3 = (uint)**(byte **)(*(int *)(*param_1 + 4) + 0x20);
      }
      else {
        uVar3 = (**(code **)(**(int **)(*param_1 + 4) + 0xc))(*(undefined4 *)(*param_1 + 4));
      }
      if (uVar3 == 0xffffffff) break;
      *param_2 = (char)uVar3;
      param_2 = param_2 + 1;
      param_1[2] = param_1[2] + 1;
      piVar1 = *(int **)(*param_1 + 4);
      if ((uint)piVar1[8] < (uint)piVar1[9]) {
        piVar1[8] = piVar1[8] + 1;
      }
      else {
        (**(code **)(*piVar1 + 0xc))(piVar1);
      }
    }
    if (uVar3 == 0xffffffff) {
      uVar3 = 3;
      if (param_3 < 0) {
        uVar3 = 1;
      }
      FUN_004dc80c(*param_1,uVar3);
    }
  }
  return param_1;
}



/* @004daf00 file=? name=FUN_004daf00 */

int * __cdecl FUN_004daf00(int *param_1,undefined4 param_2,undefined4 param_3)

{
  int iVar1;
  
  if (((*(byte *)(*param_1 + 0xc) & 0x84) == 0) &&
     (iVar1 = (**(code **)(**(int **)(*param_1 + 4) + 0x1c))
                        (*(int **)(*param_1 + 4),param_2,param_3,1), iVar1 != -1)) {
    return param_1;
  }
  FUN_004dc80c(*param_1,2);
  return param_1;
}



/* @004daf40 file=? name=FUN_004daf40 */

int * __cdecl FUN_004daf40(int *param_1,undefined4 param_2)

{
  int iVar1;
  
  if (((*(byte *)(*param_1 + 0xc) & 0x84) == 0) &&
     (iVar1 = (**(code **)(**(int **)(*param_1 + 4) + 0x20))(*(int **)(*param_1 + 4),param_2,1),
     iVar1 != -1)) {
    return param_1;
  }
  FUN_004dc80c(*param_1,2);
  return param_1;
}



/* @004daf7c file=? name=FUN_004daf7c */

int __cdecl FUN_004daf7c(int *param_1)

{
  int iVar1;
  
  iVar1 = -1;
  if (((*(byte *)(*param_1 + 0xc) & 0x84) == 0) &&
     (iVar1 = (**(code **)(**(int **)(*param_1 + 4) + 0x1c))(*(undefined4 *)(*param_1 + 4),0,1,1),
     iVar1 != -1)) {
    return iVar1;
  }
  FUN_004dc80c(*param_1,2);
  return iVar1;
}



/* @004dafd8 file=? name=FUN_004dafd8 */

void __cdecl FUN_004dafd8(undefined4 *param_1,undefined4 param_2)

{
  *param_1 = &LAB_004dafc4;
  param_1[1] = param_2;
  return;
}



/* @004dafec file=? name=FUN_004dafec */

void __cdecl FUN_004dafec(int param_1,undefined4 param_2)

{
  *(undefined4 *)(param_1 + 0x1c) = param_2;
  return;
}



/* @004db000 file=? name=FUN_004db000 */

void __cdecl FUN_004db000(undefined4 *param_1,undefined4 param_2)

{
  *param_1 = FUN_004dafec;
  param_1[1] = param_2;
  return;
}



/* @004db014 file=? name=FUN_004db014 */

int * __cdecl FUN_004db014(int *param_1,short param_2)

{
  int *piVar1;
  
  if (param_2 == 0) {
    piVar1 = param_1 + 0x13;
    *param_1 = (int)piVar1;
    param_1[0x11] = (int)piVar1;
    FUN_004dc6bc(piVar1);
  }
  FUN_004da484(param_1,1);
  FUN_004db4b0(param_1 + 0x11,1);
  param_1[1] = (int)&PTR_FUN_00520628;
  param_1[0x12] = (int)&PTR_LAB_00520634;
  *(undefined ***)*param_1 = &PTR_LAB_00520640;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004db0ec file=? name=FUN_004db0ec */

void __cdecl FUN_004db0ec(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_00520628;
    param_1[0x12] = (int)&PTR_LAB_00520634;
    *(undefined ***)*param_1 = &PTR_LAB_00520640;
    FUN_004db580(param_1 + 0x11,0);
    FUN_004da59c(param_1,0);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 0x13,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004db158 file=? name=FUN_004db158 */

int * __cdecl FUN_004db158(int *param_1,short param_2,char *param_3,int param_4,byte param_5)

{
  undefined4 *puVar1;
  int iVar2;
  undefined4 uVar3;
  undefined4 uVar4;
  
  if (param_2 == 0) {
    puVar1 = (undefined4 *)((int)param_1 + 0x46);
    *param_1 = (int)puVar1;
    *(undefined4 **)((int)param_1 + 0x3e) = puVar1;
    FUN_004dc6bc(puVar1);
  }
  FUN_004dc260(param_1,1,param_3,param_4,param_3);
  FUN_004db4f0((int *)((int)param_1 + 0x3e),1,param_1 + 2);
  param_1[1] = (int)&PTR_FUN_00520650;
  *(undefined ***)((int)param_1 + 0x42) = &PTR_LAB_0052065c;
  *(undefined ***)*param_1 = &PTR_LAB_00520668;
  if ((param_5 & 0xc) != 0) {
    uVar4 = 2;
    uVar3 = 0;
    iVar2 = FUN_004d4a78(param_3);
    (**(code **)(param_1[2] + 0x1c))(param_1 + 2,iVar2,uVar3,uVar4);
  }
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004db1e0 file=? name=FUN_004db1e0 */

int * __cdecl FUN_004db1e0(int *param_1,short param_2,char *param_3,int param_4,byte param_5)

{
  undefined4 *puVar1;
  int iVar2;
  undefined4 uVar3;
  undefined4 uVar4;
  
  if (param_2 == 0) {
    puVar1 = (undefined4 *)((int)param_1 + 0x46);
    *param_1 = (int)puVar1;
    *(undefined4 **)((int)param_1 + 0x3e) = puVar1;
    FUN_004dc6bc(puVar1);
  }
  FUN_004dc260(param_1,1,param_3,param_4,param_3);
  FUN_004db4f0((int *)((int)param_1 + 0x3e),1,param_1 + 2);
  param_1[1] = (int)&PTR_FUN_00520650;
  *(undefined ***)((int)param_1 + 0x42) = &PTR_LAB_0052065c;
  *(undefined ***)*param_1 = &PTR_LAB_00520668;
  if ((param_5 & 0xc) != 0) {
    uVar4 = 2;
    uVar3 = 0;
    iVar2 = FUN_004d4a78(param_3);
    (**(code **)(param_1[2] + 0x1c))(param_1 + 2,iVar2,uVar3,uVar4);
  }
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004db268 file=? name=FUN_004db268 */

int * __cdecl FUN_004db268(int *param_1,short param_2,char *param_3,int param_4,byte param_5)

{
  undefined4 *puVar1;
  int iVar2;
  undefined4 uVar3;
  undefined4 uVar4;
  
  if (param_2 == 0) {
    puVar1 = (undefined4 *)((int)param_1 + 0x46);
    *param_1 = (int)puVar1;
    *(undefined4 **)((int)param_1 + 0x3e) = puVar1;
    FUN_004dc6bc(puVar1);
  }
  FUN_004dc260(param_1,1,param_3,param_4,param_3);
  FUN_004db4f0((int *)((int)param_1 + 0x3e),1,param_1 + 2);
  param_1[1] = (int)&PTR_FUN_00520650;
  *(undefined ***)((int)param_1 + 0x42) = &PTR_LAB_0052065c;
  *(undefined ***)*param_1 = &PTR_LAB_00520668;
  if ((param_5 & 0xc) != 0) {
    uVar4 = 2;
    uVar3 = 0;
    iVar2 = FUN_004d4a78(param_3);
    (**(code **)(param_1[2] + 0x1c))(param_1 + 2,iVar2,uVar3,uVar4);
  }
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004db428 file=? name=FUN_004db428 */

void __cdecl FUN_004db428(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_00520650;
    *(undefined ***)((int)param_1 + 0x42) = &PTR_LAB_0052065c;
    *(undefined ***)*param_1 = &PTR_LAB_00520668;
    FUN_004db580((int *)((int)param_1 + 0x3e),0);
    FUN_004dc2c8(param_1,0);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8((int *)((int)param_1 + 0x46),0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004db494 file=? name=FUN_004db494 */

int * __cdecl FUN_004db494(int *param_1,undefined4 param_2)

{
  FUN_004dc738(*param_1,param_2);
  return param_1;
}



/* @004db4b0 file=? name=FUN_004db4b0 */

undefined4 * __cdecl FUN_004db4b0(undefined4 *param_1,short param_2)

{
  if (param_2 == 0) {
    *param_1 = param_1 + 2;
    FUN_004dc6bc(param_1 + 2);
  }
  param_1[1] = &PTR_FUN_00520678;
  *(undefined ***)*param_1 = &PTR_LAB_00520684;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004db4f0 file=? name=FUN_004db4f0 */

int * __cdecl FUN_004db4f0(int *param_1,short param_2,undefined4 param_3)

{
  undefined4 *puVar1;
  
  if (param_2 == 0) {
    *param_1 = (int)(param_1 + 2);
    FUN_004dc6bc(param_1 + 2);
  }
  param_1[1] = (int)&PTR_FUN_00520678;
  puVar1 = (undefined4 *)*param_1;
  *puVar1 = &PTR_LAB_00520684;
  FUN_004dc738((int)puVar1,param_3);
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004db534 file=? name=FUN_004db534 */

undefined4 * __cdecl FUN_004db534(undefined4 *param_1,short param_2)

{
  if (param_2 == 0) {
    *param_1 = param_1 + 2;
    FUN_004dc6bc(param_1 + 2);
  }
  FUN_004db4b0(param_1,1);
  param_1[1] = &PTR_FUN_00520694;
  *(undefined ***)*param_1 = &PTR_LAB_005206a0;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004db580 file=? name=FUN_004db580 */

void __cdecl FUN_004db580(int *param_1,uint param_2)

{
  undefined4 *puVar1;
  
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_00520678;
    puVar1 = (undefined4 *)*param_1;
    *puVar1 = &PTR_LAB_00520684;
    if (puVar1[1] != 0) {
      FUN_004db6b4(param_1);
    }
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 2,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004db5dc file=? name=FUN_004db5dc */

void __cdecl FUN_004db5dc(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_00520694;
    *(undefined ***)*param_1 = &PTR_LAB_005206a0;
    FUN_004db580(param_1,0);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8(param_1 + 2,0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004db634 file=? name=FUN_004db634 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

int * __cdecl FUN_004db634(int *param_1,float10 param_2)

{
  char *pcVar1;
  char local_40 [60];
  
  pcVar1 = (char *)0x0;
  if (((float10)_DAT_004db6b0 <= param_2) && ((*(byte *)(*param_1 + 0x19) & 4) != 0)) {
    pcVar1 = &DAT_005206a4;
  }
  thunk_FUN_004dd24c();
  FUN_004dbb24(param_1,local_40,pcVar1);
  return param_1;
}



/* @004db6b4 file=? name=FUN_004db6b4 */

int * __cdecl FUN_004db6b4(int *param_1)

{
  int iVar1;
  
  iVar1 = (**(code **)(**(int **)(*param_1 + 4) + 0x24))(*(int **)(*param_1 + 4));
  if (iVar1 == -1) {
    FUN_004dc80c(*param_1,4);
  }
  return param_1;
}



/* @004db6e0 file=? name=FUN_004db6e0 */

char * __cdecl FUN_004db6e0(char *param_1,uint param_2)

{
  *param_1 = '\0';
  do {
    param_1 = param_1 + -1;
    *param_1 = (char)((ulonglong)param_2 % 10) + '0';
    param_2 = param_2 / 10;
  } while (param_2 != 0);
  return param_1;
}



/* @004db718 file=? name=FUN_004db718 */

char * __cdecl FUN_004db718(char *param_1,uint param_2)

{
  *param_1 = '\0';
  do {
    param_1 = param_1 + -1;
    *param_1 = ((byte)param_2 & 7) + 0x30;
    param_2 = param_2 / 8;
  } while (param_2 != 0);
  return param_1;
}



/* @004db748 file=? name=FUN_004db748 */

undefined1 * __cdecl FUN_004db748(undefined1 *param_1,uint param_2,int param_3)

{
  char *pcVar1;
  
  if (param_3 == 0) {
    pcVar1 = s_0123456789abcdef0123456789ABCDEF_005206a8;
  }
  else {
    pcVar1 = s_0123456789abcdef0123456789ABCDEF_005206a8 + 0x10;
  }
  *param_1 = 0;
  do {
    param_1 = param_1 + -1;
    *param_1 = pcVar1[param_2 & 0xf];
    param_2 = param_2 / 0x10;
  } while (param_2 != 0);
  return param_1;
}



/* @004db78c file=? name=FUN_004db78c */

int * __cdecl FUN_004db78c(int *param_1,uint param_2)

{
  int iVar1;
  char *pcVar2;
  char *pcVar3;
  char local_d;
  uint local_c;
  int local_8;
  
  pcVar3 = (char *)0x0;
  if ((*(byte *)(*param_1 + 0x18) & 0x40) == 0) {
    iVar1 = 8;
    if ((*(byte *)(*param_1 + 0x18) & 0x20) == 0) {
      iVar1 = 10;
    }
  }
  else {
    iVar1 = 0x10;
  }
  if ((iVar1 == 10) && ((int)param_2 < 0)) {
    local_8 = 1;
  }
  else {
    local_8 = 0;
  }
  if (local_8 != 0) {
    param_2 = -param_2;
  }
  if (iVar1 == 10) {
    pcVar2 = FUN_004db6e0(&local_d,param_2);
    if (param_2 != 0) {
      if (local_8 == 0) {
        if ((*(byte *)(*param_1 + 0x19) & 4) != 0) {
          pcVar3 = &DAT_005206ca;
        }
      }
      else {
        pcVar3 = s_0123456789abcdef0123456789ABCDEF_005206a8 + 0x20;
      }
    }
  }
  else if (iVar1 == 0x10) {
    local_c = (uint)((*(byte *)(*param_1 + 0x19) & 2) != 0);
    pcVar2 = FUN_004db748(&local_d,param_2,local_c);
    if ((*(byte *)(*param_1 + 0x18) & 0x80) != 0) {
      if (local_c == 0) {
        pcVar3 = &DAT_005206cf;
      }
      else {
        pcVar3 = &DAT_005206cc;
      }
    }
  }
  else {
    pcVar2 = FUN_004db718(&local_d,param_2);
    if ((*(byte *)(*param_1 + 0x18) & 0x80) != 0) {
      pcVar3 = &DAT_005206d2;
    }
  }
  FUN_004dbb24(param_1,pcVar2,pcVar3);
  return param_1;
}



/* @004db880 file=? name=FUN_004db880 */

int * __cdecl FUN_004db880(int *param_1,uint param_2)

{
  char *pcVar1;
  char *pcVar2;
  char local_9;
  uint local_8;
  
  pcVar2 = (char *)0x0;
  if ((*(uint *)(*param_1 + 0x18) & 0x40) == 0) {
    if ((*(byte *)(*param_1 + 0x18) & 0x20) == 0) {
      pcVar1 = FUN_004db6e0(&local_9,param_2);
      if ((param_2 != 0) && ((*(byte *)(*param_1 + 0x19) & 4) != 0)) {
        pcVar2 = &DAT_005206dc;
      }
    }
    else {
      pcVar1 = FUN_004db718(&local_9,param_2);
      if ((*(byte *)(*param_1 + 0x18) & 0x80) != 0) {
        pcVar2 = &DAT_005206da;
      }
    }
  }
  else {
    local_8 = (uint)((*(uint *)(*param_1 + 0x18) & 0x200) != 0);
    pcVar1 = FUN_004db748(&local_9,param_2,local_8);
    if ((*(byte *)(*param_1 + 0x18) & 0x80) != 0) {
      if (local_8 == 0) {
        pcVar2 = &DAT_005206d7;
      }
      else {
        pcVar2 = &DAT_005206d4;
      }
    }
  }
  FUN_004dbb24(param_1,pcVar1,pcVar2);
  return param_1;
}



/* @004db92c file=? name=FUN_004db92c */

int * __cdecl FUN_004db92c(int *param_1,byte param_2)

{
  int *piVar1;
  byte *pbVar2;
  undefined1 *puVar3;
  int iVar4;
  uint uVar5;
  int iVar6;
  
  if (*(int *)(*param_1 + 0x14) == 0) {
    iVar4 = 1;
  }
  else {
    iVar4 = FUN_004dbabc(param_1);
  }
  if (iVar4 != 0) {
    iVar4 = *param_1;
    iVar6 = *(int *)(iVar4 + 0x20);
    *(undefined4 *)(iVar4 + 0x20) = 0;
    iVar6 = iVar6 + -1;
    if ((*(byte *)(iVar4 + 0x18) & 10) == 0) {
      do {
        iVar6 = iVar6 + -1;
        if (iVar6 < 0) goto LAB_004db9c5;
        uVar5 = *(uint *)(*param_1 + 0x24);
        if (*(uint *)(*(int *)(*param_1 + 4) + 0x14) < *(uint *)(*(int *)(*param_1 + 4) + 0x18)) {
          puVar3 = *(undefined1 **)(*(int *)(*param_1 + 4) + 0x14);
          piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x14);
          *piVar1 = *piVar1 + 1;
          *puVar3 = (char)uVar5;
          uVar5 = uVar5 & 0xff;
        }
        else {
          uVar5 = (**(code **)(**(int **)(*param_1 + 4) + 0x18))
                            (*(undefined4 *)(*param_1 + 4),uVar5 & 0xff);
        }
      } while (uVar5 != 0xffffffff);
      FUN_004dc80c(*param_1,4);
    }
LAB_004db9c5:
    if ((*(byte *)(*param_1 + 0xc) & 0x86) == 0) {
      if (*(uint *)(*(int *)(*param_1 + 4) + 0x14) < *(uint *)(*(int *)(*param_1 + 4) + 0x18)) {
        pbVar2 = *(byte **)(*(int *)(*param_1 + 4) + 0x14);
        piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x14);
        *piVar1 = *piVar1 + 1;
        *pbVar2 = param_2;
        uVar5 = (uint)param_2;
      }
      else {
        uVar5 = (**(code **)(**(int **)(*param_1 + 4) + 0x18))
                          (*(undefined4 *)(*param_1 + 4),param_2);
      }
      if (uVar5 == 0xffffffff) {
        FUN_004dc80c(*param_1,4);
      }
    }
    if (((*(byte *)(*param_1 + 0xc) & 0x86) == 0) && ((*(byte *)(*param_1 + 0x18) & 2) != 0)) {
      do {
        iVar6 = iVar6 + -1;
        if (iVar6 < 0) goto LAB_004dba91;
        uVar5 = *(uint *)(*param_1 + 0x24);
        if (*(uint *)(*(int *)(*param_1 + 4) + 0x14) < *(uint *)(*(int *)(*param_1 + 4) + 0x18)) {
          puVar3 = *(undefined1 **)(*(int *)(*param_1 + 4) + 0x14);
          piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x14);
          *piVar1 = *piVar1 + 1;
          *puVar3 = (char)uVar5;
          uVar5 = uVar5 & 0xff;
        }
        else {
          uVar5 = (**(code **)(**(int **)(*param_1 + 4) + 0x18))
                            (*(undefined4 *)(*param_1 + 4),uVar5 & 0xff);
        }
      } while (uVar5 != 0xffffffff);
      FUN_004dc80c(*param_1,4);
    }
  }
LAB_004dba91:
  if ((*(byte *)(*param_1 + 0x19) & 0x60) != 0) {
    FUN_004dbae4(param_1);
  }
  return param_1;
}



/* @004dbaa8 file=? name=FUN_004dbaa8 */

undefined4 * __cdecl FUN_004dbaa8(undefined4 *param_1,undefined *param_2)

{
  (*(code *)param_2)(*param_1);
  return param_1;
}



/* @004dbabc file=? name=FUN_004dbabc */

undefined4 __cdecl FUN_004dbabc(int *param_1)

{
  int *piVar1;
  
  if ((*(byte *)(*param_1 + 0xc) & 0x86) == 0) {
    piVar1 = *(int **)(*param_1 + 8);
    if (piVar1 != (int *)0x0) {
      FUN_004db6b4(piVar1);
    }
    return 1;
  }
  return 0;
}



/* @004dbae4 file=? name=FUN_004dbae4 */

void __cdecl FUN_004dbae4(int *param_1)

{
  if (((*(byte *)(*param_1 + 0xc) & 0x86) == 0) && ((*(byte *)(*param_1 + 0x19) & 0x20) != 0)) {
    FUN_004db6b4(param_1);
  }
  if ((*(byte *)(*param_1 + 0x19) & 0x40) != 0) {
    FUN_004db6b4(&DAT_00524e20);
    FUN_004db6b4((int *)&DAT_00524eb0);
  }
  return;
}



/* @004dbb24 file=? name=FUN_004dbb24 */

void __cdecl FUN_004dbb24(int *param_1,char *param_2,char *param_3)

{
  int *piVar1;
  undefined1 *puVar2;
  int iVar3;
  uint uVar4;
  uint uVar5;
  uint uVar6;
  int iVar7;
  
  if (*(int *)(*param_1 + 0x14) == 0) {
    iVar3 = 1;
  }
  else {
    iVar3 = FUN_004dbabc(param_1);
  }
  if (iVar3 != 0) {
    if (param_3 == (char *)0x0) {
      uVar4 = 0;
    }
    else {
      uVar4 = FUN_004d4a78(param_3);
    }
    if (param_2 == (char *)0x0) {
      uVar5 = 0;
    }
    else {
      uVar5 = FUN_004d4a78(param_2);
    }
    iVar3 = *param_1;
    iVar7 = *(int *)(iVar3 + 0x20);
    *(undefined4 *)(iVar3 + 0x20) = 0;
    iVar7 = (iVar7 - uVar4) - uVar5;
    if ((*(byte *)(iVar3 + 0x18) & 10) == 0) {
      do {
        iVar7 = iVar7 + -1;
        if (iVar7 < 0) goto LAB_004dbbf3;
        uVar6 = *(uint *)(*param_1 + 0x24);
        if (*(uint *)(*(int *)(*param_1 + 4) + 0x14) < *(uint *)(*(int *)(*param_1 + 4) + 0x18)) {
          puVar2 = *(undefined1 **)(*(int *)(*param_1 + 4) + 0x14);
          piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x14);
          *piVar1 = *piVar1 + 1;
          *puVar2 = (char)uVar6;
          uVar6 = uVar6 & 0xff;
        }
        else {
          uVar6 = (**(code **)(**(int **)(*param_1 + 4) + 0x18))
                            (*(undefined4 *)(*param_1 + 4),uVar6 & 0xff);
        }
      } while (uVar6 != 0xffffffff);
      FUN_004dc80c(*param_1,4);
    }
LAB_004dbbf3:
    if ((((*(byte *)(*param_1 + 0xc) & 0x86) == 0) && (uVar4 != 0)) &&
       (uVar6 = FUN_004dc5e4(*(int **)(*param_1 + 4),(undefined4 *)param_3,uVar4), uVar6 != uVar4))
    {
      FUN_004dc80c(*param_1,4);
    }
    if (((*(byte *)(*param_1 + 0xc) & 0x86) == 0) && ((*(byte *)(*param_1 + 0x18) & 8) != 0)) {
      do {
        iVar7 = iVar7 + -1;
        if (iVar7 < 0) goto LAB_004dbc94;
        uVar4 = *(uint *)(*param_1 + 0x24);
        if (*(uint *)(*(int *)(*param_1 + 4) + 0x14) < *(uint *)(*(int *)(*param_1 + 4) + 0x18)) {
          puVar2 = *(undefined1 **)(*(int *)(*param_1 + 4) + 0x14);
          piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x14);
          *piVar1 = *piVar1 + 1;
          *puVar2 = (char)uVar4;
          uVar4 = uVar4 & 0xff;
        }
        else {
          uVar4 = (**(code **)(**(int **)(*param_1 + 4) + 0x18))
                            (*(undefined4 *)(*param_1 + 4),uVar4 & 0xff);
        }
      } while (uVar4 != 0xffffffff);
      FUN_004dc80c(*param_1,4);
    }
LAB_004dbc94:
    if ((((*(byte *)(*param_1 + 0xc) & 0x86) == 0) && (uVar5 != 0)) &&
       (uVar4 = FUN_004dc5e4(*(int **)(*param_1 + 4),(undefined4 *)param_2,uVar5), uVar4 != uVar5))
    {
      FUN_004dc80c(*param_1,4);
    }
    if (((*(byte *)(*param_1 + 0xc) & 0x86) == 0) && ((*(byte *)(*param_1 + 0x18) & 2) != 0)) {
      do {
        iVar7 = iVar7 + -1;
        if (iVar7 < 0) goto LAB_004dbd35;
        uVar4 = *(uint *)(*param_1 + 0x24);
        if (*(uint *)(*(int *)(*param_1 + 4) + 0x14) < *(uint *)(*(int *)(*param_1 + 4) + 0x18)) {
          puVar2 = *(undefined1 **)(*(int *)(*param_1 + 4) + 0x14);
          piVar1 = (int *)(*(int *)(*param_1 + 4) + 0x14);
          *piVar1 = *piVar1 + 1;
          *puVar2 = (char)uVar4;
          uVar4 = uVar4 & 0xff;
        }
        else {
          uVar4 = (**(code **)(**(int **)(*param_1 + 4) + 0x18))
                            (*(undefined4 *)(*param_1 + 4),uVar4 & 0xff);
        }
      } while (uVar4 != 0xffffffff);
      FUN_004dc80c(*param_1,4);
    }
  }
LAB_004dbd35:
  if ((*(byte *)(*param_1 + 0x19) & 0x60) != 0) {
    FUN_004dbae4(param_1);
  }
  return;
}



/* @004dbd4c file=? name=FUN_004dbd4c */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

undefined8 __cdecl FUN_004dbd4c(int *param_1,uint param_2)

{
  char cVar1;
  undefined1 uVar2;
  int iVar3;
  uint uVar4;
  undefined4 extraout_EDX;
  
  iVar3 = *param_1;
  uVar4 = *(uint *)(iVar3 + 0x18);
  cVar1 = *(char *)(iVar3 + 0x24);
  FUN_004dc7d4(iVar3,200,DAT_0052078c | _DAT_00520790 | 0x80);
  iVar3 = *param_1;
  *(undefined4 *)(iVar3 + 0x24) = 0x30;
  *(undefined4 *)(iVar3 + 0x20) = 10;
  FUN_004db880(param_1,param_2);
  FUN_004dc710(*param_1,uVar4);
  uVar2 = *(undefined1 *)(*param_1 + 0x24);
  *(int *)(*param_1 + 0x24) = (int)cVar1;
  return CONCAT44(CONCAT31((int3)((uint)extraout_EDX >> 8),uVar2),param_1);
}



/* @004dbdbc file=? name=FUN_004dbdbc */

undefined4 * __cdecl FUN_004dbdbc(undefined4 *param_1,char *param_2,int param_3,char *param_4)

{
  FUN_004dc35c(param_1);
  *param_1 = &PTR_FUN_005206ec;
  FUN_004dbeb0((int)param_1,param_2,param_3,param_4);
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004dbdf1 file=? name=FUN_004dbdf1 */

void FUN_004dbdf1(void)

{
  return;
}



/* @004dbdf6 file=? name=FUN_004dbdf6 */

void FUN_004dbdf6(void)

{
  return;
}



/* @004dbe58 file=? name=FUN_004dbe58 */

void __cdecl FUN_004dbe58(int *param_1,byte param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    *param_1 = (int)&PTR_FUN_005206ec;
    if ((*(ushort *)(param_1 + 0xc) & 3) == 1) {
      if (param_1[0xb] == 0) {
        FUN_004022e8((int *)param_1[2]);
      }
      else {
        (*(code *)param_1[0xb])(param_1[2]);
      }
    }
    FUN_004dc48c(param_1,0);
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004dbeb0 file=? name=FUN_004dbeb0 */

void __cdecl FUN_004dbeb0(int param_1,char *param_2,int param_3,char *param_4)

{
  *(undefined2 *)(param_1 + 0x30) = 0;
  if (param_3 == 0) {
    param_3 = FUN_004d4a78(param_2);
  }
  else if (param_3 < 0) {
    param_3 = 0x7fffffff;
    *(ushort *)(param_1 + 0x30) = *(ushort *)(param_1 + 0x30) | 4;
  }
  FUN_004dc4fc(param_1,(uint)param_2,(uint)(param_2 + param_3),0);
  if (param_4 == (char *)0x0) {
    FUN_004dc564(param_1,(uint)param_2,(uint)param_2,*(uint *)(param_1 + 0xc));
  }
  else {
    FUN_004dc598(param_1,(uint)param_4,*(uint *)(param_1 + 0xc));
    if (param_2 + param_3 < param_4) {
      param_4 = param_2 + param_3;
    }
    FUN_004dc564(param_1,(uint)param_2,(uint)param_2,(uint)param_4);
  }
  *(undefined4 *)(param_1 + 0x28) = 0;
  *(undefined4 *)(param_1 + 0x2c) = 0;
  return;
}



/* @004dbf44 file=? name=FUN_004dbf44 */

uint __cdecl FUN_004dbf44(int *param_1,byte param_2)

{
  int *piVar1;
  int iVar2;
  int iVar3;
  byte *pbVar4;
  undefined4 *puVar5;
  uint uVar6;
  int local_14;
  int local_10;
  int local_c;
  
  if ((*(ushort *)(param_1 + 0xc) & 3) == 1) {
    if (param_1[2] == 0) {
      (**(code **)(*param_1 + 0x30))(param_1);
    }
    if (param_1[4] == 0) {
      FUN_004dc598((int)param_1,param_1[2],param_1[3]);
    }
  }
  if (param_1[4] != 0) {
    if (((uint)param_1[6] <= (uint)param_1[5]) && ((*(ushort *)(param_1 + 0xc) & 3) == 1)) {
      piVar1 = (int *)param_1[2];
      uVar6 = param_1[3] - (int)piVar1;
      puVar5 = (undefined4 *)FUN_004022b0(uVar6 + 4);
      if (puVar5 == (undefined4 *)0x0) {
        return 0xffffffff;
      }
      FUN_004d4918(puVar5,piVar1,uVar6);
      iVar2 = param_1[5];
      iVar3 = param_1[8];
      if (iVar3 != 0) {
        local_c = param_1[7] - (int)piVar1;
        local_10 = iVar3 - (int)piVar1;
        local_14 = param_1[9] - (int)piVar1;
      }
      FUN_004dc4fc((int)param_1,(uint)puVar5,(int)puVar5 + uVar6 + 4,0);
      FUN_004dc598((int)param_1,(uint)puVar5,param_1[3]);
      param_1[5] = param_1[5] + (iVar2 - (int)piVar1);
      if (iVar3 != 0) {
        FUN_004dc564((int)param_1,(int)puVar5 + local_c,local_10 + (int)puVar5,
                     local_14 + (int)puVar5);
      }
      FUN_004022e8(piVar1);
    }
    if ((uint)param_1[5] < (uint)param_1[6]) {
      if ((uint)param_1[6] <= (uint)param_1[5]) {
        uVar6 = (**(code **)(*param_1 + 0x18))(param_1,param_2);
        return uVar6;
      }
      pbVar4 = (byte *)param_1[5];
      param_1[5] = param_1[5] + 1;
      *pbVar4 = param_2;
      return (uint)param_2;
    }
  }
  return 0xffffffff;
}



/* @004dc260 file=? name=FUN_004dc260 */

int * __cdecl FUN_004dc260(int *param_1,short param_2,char *param_3,int param_4,char *param_5)

{
  if (param_2 == 0) {
    *param_1 = (int)param_1 + 0x3e;
    FUN_004dc6bc((undefined4 *)((int)param_1 + 0x3e));
  }
  param_1[1] = (int)&PTR_FUN_0052072c;
  *(undefined ***)*param_1 = &PTR_LAB_00520738;
  FUN_004dbdbc(param_1 + 2,param_3,param_4,param_5);
  FUN_004dc738(*param_1,param_1 + 2);
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return param_1;
}



/* @004dc2c8 file=? name=FUN_004dc2c8 */

void __cdecl FUN_004dc2c8(int *param_1,uint param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    param_1[1] = (int)&PTR_FUN_0052072c;
    *(undefined ***)*param_1 = &PTR_LAB_00520738;
    FUN_004dbe58(param_1 + 2,2);
    if ((param_2 & 2) != 0) {
      FUN_004dc6d8((int *)((int)param_1 + 0x3e),0);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004dc35c file=? name=FUN_004dc35c */

void __cdecl FUN_004dc35c(undefined4 *param_1)

{
  *param_1 = &PTR_FUN_00520748;
  *(undefined2 *)(param_1 + 1) = 0;
  *(undefined2 *)((int)param_1 + 6) = 0;
  param_1[2] = 0;
  param_1[4] = 0;
  param_1[5] = 0;
  param_1[6] = 0;
  param_1[8] = 0;
  param_1[9] = 0;
  param_1[7] = 0;
  param_1[3] = 0;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return;
}



/* @004dc41c file=? name=FUN_004dc41c */

uint __cdecl FUN_004dc41c(int *param_1,byte *param_2,uint param_3)

{
  byte bVar1;
  byte *pbVar2;
  uint uVar3;
  uint uVar4;
  
  uVar4 = param_1[6] - param_1[5];
  if (0 < (int)uVar4) {
    FUN_004d4918((undefined4 *)param_1[5],(undefined4 *)param_2,uVar4);
    param_1[5] = param_1[5] + uVar4;
    param_2 = param_2 + uVar4;
  }
  while( true ) {
    if (param_3 <= uVar4) {
      return uVar4;
    }
    bVar1 = *param_2;
    if ((uint)param_1[5] < (uint)param_1[6]) {
      pbVar2 = (byte *)param_1[5];
      param_1[5] = param_1[5] + 1;
      *pbVar2 = bVar1;
      uVar3 = (uint)bVar1;
    }
    else {
      uVar3 = (**(code **)(*param_1 + 0x18))(param_1,bVar1);
    }
    if (uVar3 == 0xffffffff) break;
    uVar4 = uVar4 + 1;
    param_2 = param_2 + 1;
  }
  return uVar4;
}



/* @004dc48c file=? name=FUN_004dc48c */

void __cdecl FUN_004dc48c(int *param_1,byte param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    *param_1 = (int)&PTR_FUN_00520748;
    if ((short)param_1[1] != 0) {
      FUN_004022e8((int *)param_1[2]);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004dc4d0 file=? name=FUN_004dc4d0 */

undefined4 FUN_004dc4d0(void)

{
  return 0xffffffff;
}



/* @004dc4d8 file=? name=FUN_004dc4d8 */

int __cdecl FUN_004dc4d8(int param_1,uint param_2,int param_3)

{
  FUN_004dc4fc(param_1,param_2,param_3 + param_2,0);
  return param_1;
}



/* @004dc4fc file=? name=FUN_004dc4fc */

void __cdecl FUN_004dc4fc(int param_1,uint param_2,uint param_3,int param_4)

{
  undefined2 uVar1;
  
  if (((*(short *)(param_1 + 4) != 0) && (*(int *)(param_1 + 8) != 0)) &&
     (param_2 != *(uint *)(param_1 + 8))) {
    FUN_004022e8(*(int **)(param_1 + 8));
  }
  *(uint *)(param_1 + 8) = param_2;
  if (((param_2 == 0) || (param_3 == 0)) || (param_3 < param_2)) {
    param_3 = param_2;
  }
  *(uint *)(param_1 + 0xc) = param_3;
  *(ushort *)(param_1 + 6) = (ushort)(param_2 == 0);
  if ((param_4 == 0) || (param_2 == 0)) {
    uVar1 = 0;
  }
  else {
    uVar1 = 1;
  }
  *(undefined2 *)(param_1 + 4) = uVar1;
  return;
}



/* @004dc564 file=? name=FUN_004dc564 */

void __cdecl FUN_004dc564(int param_1,uint param_2,uint param_3,uint param_4)

{
  if ((param_3 == 0) || (param_2 == 0)) {
    param_2 = param_3;
  }
  *(uint *)(param_1 + 0x1c) = param_2;
  *(uint *)(param_1 + 0x20) = param_3;
  if (((param_3 == 0) || (param_4 == 0)) || (param_4 < param_3)) {
    param_4 = param_3;
  }
  *(uint *)(param_1 + 0x24) = param_4;
  return;
}



/* @004dc598 file=? name=FUN_004dc598 */

void __cdecl FUN_004dc598(int param_1,uint param_2,uint param_3)

{
  *(uint *)(param_1 + 0x14) = param_2;
  *(uint *)(param_1 + 0x10) = param_2;
  if (((param_2 == 0) || (param_3 == 0)) || (param_3 < param_2)) {
    param_3 = param_2;
  }
  *(uint *)(param_1 + 0x18) = param_3;
  return;
}



/* @004dc5c8 file=? name=FUN_004dc5c8 */

void __cdecl FUN_004dc5c8(int *param_1,undefined4 param_2,undefined4 param_3)

{
  (**(code **)(*param_1 + 0x1c))(param_1,param_2,0,param_3);
  return;
}



/* @004dc5e4 file=? name=FUN_004dc5e4 */

uint __cdecl FUN_004dc5e4(int *param_1,undefined4 *param_2,uint param_3)

{
  if ((uint)(param_1[6] - param_1[5]) < param_3) {
    param_3 = (**(code **)(*param_1 + 0x14))(param_1,param_2,param_3);
  }
  else {
    FUN_004d4918((undefined4 *)param_1[5],param_2,param_3);
    param_1[5] = param_1[5] + param_3;
  }
  return param_3;
}



/* @004dc680 file=? name=FUN_004dc680 */

void __cdecl FUN_004dc680(int param_1,uint param_2)

{
  uint uVar1;
  
  uVar1 = param_2 & 0xff | *(uint *)(param_1 + 0xc) & 0x80;
  *(uint *)(param_1 + 0xc) = uVar1;
  *(uint *)(param_1 + 0x10) = *(uint *)(param_1 + 0x10) & 0xffffff00 | uVar1;
  *(uint *)(param_1 + 0x14) = *(uint *)(param_1 + 0x14) & 0xffffff00 | *(uint *)(param_1 + 0xc);
  return;
}



/* @004dc6bc file=? name=FUN_004dc6bc */

void __cdecl FUN_004dc6bc(undefined4 *param_1)

{
  *param_1 = &PTR_FUN_00520788;
  param_1[0xe] = 0;
  *DAT_00524c68 = *DAT_00524c68 + 1;
  return;
}



/* @004dc6d8 file=? name=FUN_004dc6d8 */

void __cdecl FUN_004dc6d8(int *param_1,byte param_2)

{
  *DAT_00524c68 = *DAT_00524c68 + -1;
  if (param_1 != (int *)0x0) {
    *param_1 = (int)&PTR_FUN_00520788;
    if ((int *)param_1[0xe] != (int *)0x0) {
      FUN_004022e8((int *)param_1[0xe]);
    }
    if ((param_2 & 1) != 0) {
      FUN_004022d0(param_1);
    }
  }
  return;
}



/* @004dc710 file=? name=FUN_004dc710 */

undefined4 __cdecl FUN_004dc710(int param_1,uint param_2)

{
  undefined4 uVar1;
  
  uVar1 = *(undefined4 *)(param_1 + 0x18);
  *(uint *)(param_1 + 0x18) = param_2;
  if ((param_2 & 1) == 0) {
    *(uint *)(param_1 + 0x10) = *(uint *)(param_1 + 0x10) & 0xfffffeff;
  }
  else {
    *(uint *)(param_1 + 0x10) = *(uint *)(param_1 + 0x10) | 0x100;
  }
  return uVar1;
}



/* @004dc738 file=? name=FUN_004dc738 */

void __cdecl FUN_004dc738(int param_1,undefined4 param_2)

{
  *(undefined4 *)(param_1 + 0x3c) = 0;
  *(undefined4 *)(param_1 + 0x14) = 0;
  *(undefined4 *)(param_1 + 0xc) = 0;
  *(undefined4 *)(param_1 + 0x10) = 0x100;
  *(undefined4 *)(param_1 + 0x18) = 1;
  *(undefined4 *)(param_1 + 0x1c) = 6;
  *(undefined4 *)(param_1 + 0x20) = 0;
  *(undefined4 *)(param_1 + 0x24) = 0x20;
  *(undefined4 *)(param_1 + 8) = 0;
  *(undefined4 *)(param_1 + 4) = param_2;
  return;
}



/* @004dc7d4 file=? name=FUN_004dc7d4 */

undefined4 __cdecl FUN_004dc7d4(int param_1,uint param_2,uint param_3)

{
  undefined4 uVar1;
  
  uVar1 = *(undefined4 *)(param_1 + 0x18);
  *(uint *)(param_1 + 0x18) = *(uint *)(param_1 + 0x18) & ~param_3;
  *(uint *)(param_1 + 0x18) = *(uint *)(param_1 + 0x18) | param_3 & param_2;
  if ((*(byte *)(param_1 + 0x18) & 1) == 0) {
    *(uint *)(param_1 + 0x10) = *(uint *)(param_1 + 0x10) & 0xfffffeff;
  }
  else {
    *(uint *)(param_1 + 0x10) = *(uint *)(param_1 + 0x10) | 0x100;
  }
  return uVar1;
}



/* @004dc80c file=? name=FUN_004dc80c */

void __cdecl FUN_004dc80c(int param_1,uint param_2)

{
  *(uint *)(param_1 + 0xc) = *(uint *)(param_1 + 0xc) | param_2 & 0xff;
  *(uint *)(param_1 + 0x10) = *(uint *)(param_1 + 0x10) | param_2 & 0xfffffcff;
  *(uint *)(param_1 + 0x14) = *(uint *)(param_1 + 0x14) | param_2 & 0xfffffdff;
  return;
}



/* @004dc888 file=? name=FUN_004dc888 */

void FUN_004dc888(void)

{
  return;
}



/* @004dc89c file=? name=FUN_004dc89c */

uint __cdecl FUN_004dc89c(uint param_1)

{
  uint uVar1;
  
  if (param_1 == 0xffffffff) {
    return 0xffffffff;
  }
  uVar1 = param_1 & 0xff;
  if (((&DAT_005207dd)[uVar1] & 4) != 0) {
    return uVar1 + 0x20;
  }
  return uVar1;
}



/* @004dc8c4 file=? name=FUN_004dc8c4 */

uint __cdecl FUN_004dc8c4(uint param_1)

{
  uint uVar1;
  
  if (param_1 == 0xffffffff) {
    return 0xffffffff;
  }
  uVar1 = param_1 & 0xff;
  if (((&DAT_005207dd)[uVar1] & 8) != 0) {
    return uVar1 - 0x20;
  }
  return uVar1;
}



/* @004dc8ec file=? name=FUN_004dc8ec */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

float10 __cdecl FUN_004dc8ec(double param_1,undefined4 param_2,uint param_3)

{
  ushort uVar1;
  ushort uVar2;
  float10 fVar3;
  
  uVar1 = (ushort)((ulonglong)param_1 >> 0x30) & 0xfff0;
  uVar2 = uVar1 << 1;
  if (uVar2 == 0) {
    if ((param_3 & 0x7ff00000) != 0) {
      if (-1 < (short)(param_3._2_2_ & 0xfff0)) {
        return (float10)param_1;
      }
      if (-1 < (short)uVar1) {
        return (float10)3.141592653589793;
      }
      return -(float10)3.141592653589793;
    }
LAB_004dc975:
    fVar3 = FUN_004de098(1,s_atan2_005208f6,(undefined8 *)&param_2,&param_1,DAT_005208ee,
                         DAT_005208f2);
    return fVar3;
  }
  uVar1 = (param_3._2_2_ & 0xfff0) << 1;
  if (uVar1 == 0) {
LAB_004dc953:
    fVar3 = _DAT_005208e4;
    if (((ulonglong)param_1 & 0x8000000000000000) != 0) {
      fVar3 = -_DAT_005208e4;
    }
  }
  else {
    if (uVar1 < 0xffe0) {
      if (0xffdf < uVar2) goto LAB_004dc953;
      fVar3 = (float10)FUN_004dcaa4();
    }
    else {
      if (0xffdf < uVar2) goto LAB_004dc975;
      fVar3 = (float10)0;
    }
    if ((param_3 & 0x80000000) != 0) {
      if ((param_1._7_1_ & 0x80) == 0) {
        fVar3 = (float10)3.141592653589793 + fVar3;
      }
      else {
        fVar3 = fVar3 - (float10)3.141592653589793;
      }
    }
  }
  return fVar3;
}



/* @004dc9a0 file=? name=FUN_004dc9a0 */

undefined2 FUN_004dc9a0(void)

{
  undefined2 in_FPUStatusWord;
  
  return in_FPUStatusWord;
}



/* @004dc9b4 file=? name=FUN_004dc9b4 */

void __cdecl FUN_004dc9b4(undefined4 param_1,undefined4 param_2)

{
  if ((param_2._2_2_ & 0x7ff0) < 0x4340) {
    FUN_004dcc20();
  }
  else {
    FUN_004de098(5,&DAT_00520904,(undefined8 *)&param_1,(undefined8 *)0x0,DAT_005208fc,DAT_00520900)
    ;
  }
  return;
}



/* @004dc9f8 file=? name=FUN_004dc9f8 */

void FUN_004dc9f8(void)

{
  return;
}



/* @004dca20 file=? name=thunk_FUN_004dd24c */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void thunk_FUN_004dd24c(void)

{
                    /* WARNING: Could not recover jumptable at 0x004dca20. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  (*_DAT_00520964)();
  return;
}



/* @004dca26 file=? name=thunk_FUN_004dd24c */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void thunk_FUN_004dd24c(void)

{
                    /* WARNING: Could not recover jumptable at 0x004dca26. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  (*_DAT_00520968)();
  return;
}



/* @004dca2c file=? name=thunk_FUN_004dd258 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void thunk_FUN_004dd258(void)

{
                    /* WARNING: Could not recover jumptable at 0x004dca2c. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  (*_DAT_0052096c)();
  return;
}



/* @004dca32 file=? name=thunk_FUN_004dd258 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void thunk_FUN_004dd258(void)

{
                    /* WARNING: Could not recover jumptable at 0x004dca32. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  (*_DAT_00520970)();
  return;
}



/* @004dca38 file=? name=FUN_004dca38 */

void __thiscall FUN_004dca38(undefined2 param_1,undefined4 param_2,uint param_3)

{
  ushort uVar1;
  undefined4 *puVar2;
  int iVar3;
  
  if (0x4085 < (param_3._2_2_ & 0x7fff)) {
    uVar1 = 0xffff;
    if ((param_3._2_2_ & 0x7fff) < 0x4087) {
      uVar1 = (ushort)param_3;
    }
    if ((param_3 & 0x80000000) == 0) {
      if (0x2e41 < uVar1) {
        iVar3 = 3;
        puVar2 = &DAT_005209d4;
LAB_004dca87:
        FUN_004de098(iVar3,&DAT_00520910,(undefined8 *)&param_2,(undefined8 *)0x0,*puVar2,puVar2[1])
        ;
        return;
      }
    }
    else if (0x232a < uVar1) {
      iVar3 = 4;
      puVar2 = &DAT_00520908;
      goto LAB_004dca87;
    }
  }
  FUN_004dcb11(param_1);
  return;
}



/* @004dcaa4 file=? name=FUN_004dcaa4 */

void FUN_004dcaa4(void)

{
  float10 fVar1;
  float10 in_ST0;
  float10 fVar2;
  float10 fVar3;
  
  if (in_ST0 != (float10)0) {
    fVar2 = ABS(in_ST0);
    fVar1 = (float10)1;
    if (fVar1 != fVar2) {
      fVar3 = fVar1;
      if (fVar1 < fVar2) {
        fVar3 = fVar2;
        fVar2 = fVar1;
      }
      fpatan(fVar2,fVar3);
    }
  }
  return;
}



/* @004dcb11 file=? name=FUN_004dcb11 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void __fastcall FUN_004dcb11(undefined2 param_1)

{
  ushort uVar1;
  short sVar2;
  float10 in_ST0;
  float10 fVar3;
  float10 fVar4;
  
  sVar2 = CONCAT11((char)((ushort)param_1 >> 8),1);
  fVar4 = in_ST0;
  fVar3 = (float10)1.4426950408889634;
  if (sVar2 != 0) {
    fVar4 = (float10)1.4426950408889634;
    fVar3 = in_ST0;
  }
  if (in_ST0 != (float10)0) {
    if (sVar2 != 0) {
      fVar4 = fVar4 * fVar3;
    }
    fVar4 = ABS(fVar4);
    if ((float10)_DAT_005213bc < fVar4) {
      fVar3 = (float10)fscale(fVar4,(float10)1);
      uVar1 = (ushort)ROUND(ROUND(fVar3));
      fVar3 = (float10)fscale(ROUND(fVar3),-(float10)1);
      fVar4 = (float10)f2xm1(fVar4 - fVar3);
      fVar4 = (float10)1 + fVar4;
      if ((uVar1 & 1) != 0) {
        fVar4 = _DAT_005213c0 * fVar4;
      }
      fscale(fVar4,(float10)(uVar1 >> 1));
    }
    else {
      f2xm1(fVar4);
    }
  }
  return;
}



/* @004dcbdc file=? name=FUN_004dcbdc */

void FUN_004dcbdc(void)

{
  float10 in_ST0;
  
  if ((in_ST0 != (float10)0) && ((float10)0 <= in_ST0)) {
    log2(in_ST0);
  }
  return;
}



/* @004dcc1c file=? name=FUN_004dcc1c */

/* WARNING: Removing unreachable block (ram,0x004dcc96) */
/* WARNING: Removing unreachable block (ram,0x004dcc3e) */
/* WARNING: Removing unreachable block (ram,0x004dcccd) */
/* WARNING: Removing unreachable block (ram,0x004dccd8) */
/* WARNING: Removing unreachable block (ram,0x004dccda) */
/* WARNING: Removing unreachable block (ram,0x004dccde) */
/* WARNING: Removing unreachable block (ram,0x004dccee) */
/* WARNING: Removing unreachable block (ram,0x004dccf8) */
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void FUN_004dcc1c(void)

{
  float10 fVar1;
  byte bVar2;
  float10 in_ST0;
  float10 fVar3;
  byte bStack_3;
  
  if (in_ST0 != (float10)0) {
    fVar1 = (float10)0;
    bVar2 = NAN(_DAT_005213e8) | (byte)((ushort)((ushort)(_DAT_005213e8 < fVar1) << 9) >> 8);
    bStack_3 = bVar2 | (byte)((ushort)((ushort)(_DAT_005213e8 != fVar1) << 10) >> 8) |
               (byte)((ushort)((ushort)(_DAT_005213e8 == fVar1) << 0xe) >> 8);
    fVar3 = ABS(in_ST0) - (float10)(unkint10)(ABS(in_ST0) / _DAT_005213e8) * _DAT_005213e8;
    if ((_DAT_005213e8 != fVar1) == 0) {
      if (3 < (byte)(bVar2 << 1 | (char)(bStack_3 << 1) < '\0')) {
        fVar3 = _DAT_005213e8 - fVar3;
      }
      fptan(fVar3);
    }
  }
  return;
}



/* @004dcc20 file=? name=FUN_004dcc20 */

/* WARNING: Removing unreachable block (ram,0x004dcccd) */
/* WARNING: Removing unreachable block (ram,0x004dccd8) */
/* WARNING: Removing unreachable block (ram,0x004dccda) */
/* WARNING: Removing unreachable block (ram,0x004dccde) */
/* WARNING: Removing unreachable block (ram,0x004dccee) */
/* WARNING: Removing unreachable block (ram,0x004dccf8) */
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void FUN_004dcc20(void)

{
  float10 fVar1;
  byte bVar2;
  float10 in_ST0;
  float10 fVar3;
  byte bStack_3;
  
  if (in_ST0 != (float10)0) {
    fVar1 = (float10)0;
    bVar2 = NAN(_DAT_005213e8) | (byte)((ushort)((ushort)(_DAT_005213e8 < fVar1) << 9) >> 8);
    bStack_3 = bVar2 | (byte)((ushort)((ushort)(_DAT_005213e8 != fVar1) << 10) >> 8) |
               (byte)((ushort)((ushort)(_DAT_005213e8 == fVar1) << 0xe) >> 8);
    fVar3 = ABS(in_ST0) - (float10)(unkint10)(ABS(in_ST0) / _DAT_005213e8) * _DAT_005213e8;
    if ((_DAT_005213e8 != fVar1) == 0) {
      if (3 < (byte)(bVar2 << 1 | (char)(bStack_3 << 1) < '\0')) {
        fVar3 = _DAT_005213e8 - fVar3;
      }
      fptan(fVar3);
    }
  }
  return;
}



/* @004dcc24 file=? name=FUN_004dcc24 */

/* WARNING: Removing unreachable block (ram,0x004dcc96) */
/* WARNING: Removing unreachable block (ram,0x004dcc3e) */
/* WARNING: Removing unreachable block (ram,0x004dccad) */
/* WARNING: Removing unreachable block (ram,0x004dccb1) */
/* WARNING: Removing unreachable block (ram,0x004dccb3) */
/* WARNING: Removing unreachable block (ram,0x004dccc7) */
/* WARNING: Removing unreachable block (ram,0x004dccc9) */
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void FUN_004dcc24(void)

{
  float10 fVar1;
  byte bVar2;
  float10 in_ST0;
  float10 fVar3;
  byte bStack_3;
  
  if (in_ST0 != (float10)0) {
    fVar1 = (float10)0;
    bVar2 = NAN(_DAT_005213e8) | (byte)((ushort)((ushort)(_DAT_005213e8 < fVar1) << 9) >> 8);
    bStack_3 = bVar2 | (byte)((ushort)((ushort)(_DAT_005213e8 != fVar1) << 10) >> 8) |
               (byte)((ushort)((ushort)(_DAT_005213e8 == fVar1) << 0xe) >> 8);
    fVar3 = ABS(in_ST0) - (float10)(unkint10)(ABS(in_ST0) / _DAT_005213e8) * _DAT_005213e8;
    if ((_DAT_005213e8 != fVar1) == 0) {
      if (3 < (byte)(bVar2 << 1 | (char)(bStack_3 << 1) < '\0')) {
        fVar3 = _DAT_005213e8 - fVar3;
      }
      fptan(fVar3);
    }
  }
  return;
}



/* @004dcd00 file=? name=FUN_004dcd00 */

float10 __cdecl FUN_004dcd00(double param_1)

{
  return (float10)ABS(param_1);
}



/* @004dcd10 file=? name=FUN_004dcd10 */

float10 __cdecl FUN_004dcd10(double param_1)

{
  float10 fVar1;
  
  fVar1 = (float10)param_1;
  if ((ushort)(param_1._6_2_ * 2) < 0x8681) {
    fVar1 = FUN_004dd0c8();
  }
  return fVar1;
}



/* @004dcd2c file=? name=FUN_004dcd2c */

float10 __cdecl FUN_004dcd2c(double param_1,double param_2)

{
  ushort in_FPUStatusWord;
  float10 fVar1;
  
  if ((ushort)(param_2._6_2_ << 1) != 0) {
    if (0xffdf < (ushort)(param_2._6_2_ << 1)) {
      return (float10)param_1;
    }
    fVar1 = (float10)param_1;
    if (((ushort)(param_1._6_2_ << 1) != 0) && ((ushort)(param_1._6_2_ << 1) < 0xffe0)) {
      do {
        fVar1 = fVar1 - (float10)(unkint10)(fVar1 / (float10)param_2) * (float10)param_2;
      } while ((in_FPUStatusWord & 0x400) != 0);
      return fVar1;
    }
  }
  return (float10)0;
}



/* @004dcd7c file=? name=FUN_004dcd7c */

void FUN_004dcd7c(void)

{
  FUN_004dc9f8();
  return;
}



/* @004dcd94 file=? name=FUN_004dcd94 */

undefined4 FUN_004dcd94(void)

{
  float10 in_ST0;
  undefined4 local_10;
  
  local_10 = (undefined4)(longlong)ROUND(in_ST0);
  return local_10;
}



/* @004dcdec file=? name=FUN_004dcdec */

void __cdecl FUN_004dcdec(longlong *param_1,float10 *param_2)

{
  if (*(short *)((int)param_2 + 8) != 0x403e) {
    *param_1 = (longlong)ROUND(*param_2);
    return;
  }
  *(undefined4 *)param_1 = *(undefined4 *)param_2;
  *(undefined4 *)((int)param_1 + 4) = *(undefined4 *)((int)param_2 + 4);
  return;
}



/* @004dce10 file=? name=FUN_004dce10 */

ushort __cdecl FUN_004dce10(float10 *param_1)

{
  float10 fVar1;
  float10 fVar2;
  
  fVar1 = *param_1;
  fVar2 = (float10)0;
  return (ushort)NAN(fVar1) << 8 | (ushort)(fVar1 < fVar2) << 9 | (ushort)(fVar1 != fVar2) << 10 |
         (ushort)(fVar1 == fVar2) << 0xe;
}



/* @004dce24 file=? name=FUN_004dce24 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void __cdecl FUN_004dce24(undefined4 param_1,int param_2)

{
  double *pdVar1;
  int iVar2;
  double local_c;
  
  if ((short)(param_2._2_2_ * 2) == 0) {
    iVar2 = 2;
    local_c = -_DAT_005209d4;
    pdVar1 = &local_c;
  }
  else if (param_2 < 0) {
    iVar2 = 1;
    pdVar1 = (double *)&DAT_00520914;
  }
  else {
    if ((short)(param_2._2_2_ * 2) != -0x20) {
      FUN_004dcbdc();
      return;
    }
    iVar2 = 3;
    pdVar1 = (double *)&DAT_005209d4;
  }
  FUN_004de098(iVar2,&DAT_0052091c,(undefined8 *)&param_1,(undefined8 *)0x0,*(undefined4 *)pdVar1,
               *(undefined4 *)((int)pdVar1 + 4));
  return;
}



/* @004dce94 file=? name=FUN_004dce94 */

/* WARNING: Removing unreachable block (ram,0x004dcf54) */

float10 __cdecl FUN_004dce94(double param_1,undefined4 param_2,uint param_3)

{
  double dVar1;
  char cVar2;
  ushort uVar3;
  byte bVar4;
  undefined2 extraout_CX;
  double *pdVar5;
  ushort uVar6;
  int iVar7;
  short sVar8;
  bool bVar9;
  float10 fVar10;
  float10 fVar11;
  ushort uStack_10;
  undefined2 uStack_e;
  double local_c;
  
  bVar9 = false;
  fVar10 = (float10)param_1;
  uVar6 = (ushort)((ulonglong)param_1 >> 0x30);
  uVar3 = (ushort)(param_3 >> 0x10);
  if (((ulonglong)param_1 & 0x7ff0000000000000) == 0) {
    if (0xffff < (int)param_3) {
      return (float10)0;
    }
    iVar7 = 1;
    if (uVar3 == 0) {
      pdVar5 = (double *)&DAT_00520930;
    }
    else {
      pdVar5 = (double *)&DAT_005209d4;
    }
  }
  else {
    if ((uVar6 & 0x7ff0) == 0x7ff0) {
      local_c = param_1;
      if ((int)param_3 < 0) {
        iVar7 = 4;
        pdVar5 = (double *)&DAT_00520928;
        goto LAB_004dcf19;
      }
    }
    else {
      dVar1 = (double)CONCAT17(param_3._3_1_,
                               CONCAT16(param_3._2_1_,CONCAT24((undefined2)param_3,param_2)));
      uVar3 = uVar3 & 0x7ff0;
      if ((param_3 & 0x7ff00000) == 0) {
        return (float10)1;
      }
      if (uVar3 != 0x7ff0) {
        uVar3 = uVar3 >> 4;
        if ((ushort)(uVar3 - 0x3ff) < 0x3f) {
          if (((byte)(uVar3 - 0x3ff) < 0xc) &&
             (sVar8 = uVar6 * 2 + -0x7fe0, bVar4 = (char)uVar3 + 2, uVar3 = uVar3 - 0x3ff,
             (short)(sVar8 << (bVar4 & 0x1f)) >> (bVar4 & 0x1f) == sVar8)) {
            uVar6 = (ushort)CONCAT31((int3)((param_3 & 0xfff0) >> 8),
                                     (byte)(param_3 & 0xfff0) | param_3._2_1_ & 0xf);
            uVar6 = uVar6 >> 4 | uVar6 << 0xc;
            fVar11 = fVar10;
            while (cVar2 = (char)uVar3, uVar3 = (ushort)(byte)(cVar2 - 1), '\0' < cVar2) {
              fVar11 = fVar11 * fVar11;
              bVar9 = (short)uVar6 < 0;
              uVar6 = uVar6 << 1;
              if (bVar9) {
                fVar11 = fVar11 * fVar10;
              }
            }
            if ((param_3 & 0x80000000) == 0) {
              return fVar11;
            }
            return (float10)1 / fVar11;
          }
          local_c = (double)(longlong)ROUND(ROUND(dVar1));
          if ((((ulonglong)param_1 & 0x8000000000000000) != 0) &&
             (fVar10 = -fVar10, ((ulonglong)local_c & 1) != 0)) {
            bVar9 = true;
          }
        }
        if (fVar10 < (float10)0) {
          iVar7 = 1;
          pdVar5 = (double *)&DAT_00520920;
          goto LAB_004dcf19;
        }
        fVar10 = (float10)FUN_004dcbdc();
        fVar10 = fVar10 * (float10)(double)CONCAT17(param_3._3_1_,
                                                    CONCAT16(param_3._2_1_,
                                                             CONCAT24((undefined2)param_3,param_2)))
        ;
        uStack_e = (ushort)((unkuint10)fVar10 >> 0x40);
        if ((uStack_e & 0x7fff) < 0x4008) {
LAB_004dcfc5:
          fVar10 = (float10)FUN_004dcb11(extraout_CX);
          if (!bVar9) {
            return fVar10;
          }
          return -fVar10;
        }
        uStack_10 = 0xffff;
        if ((uStack_e & 0x7fff) < 0x4009) {
          uStack_10 = (ushort)((unkuint10)fVar10 >> 0x30);
        }
        uStack_e._1_1_ = (byte)((unkuint10)fVar10 >> 0x48);
        if ((uStack_e._1_1_ & 0x80) == 0) {
          if (uStack_10 < 0xb172) goto LAB_004dcfc5;
          iVar7 = 3;
          pdVar5 = (double *)&DAT_005209d4;
        }
        else {
          if (uStack_10 < 0xb172) goto LAB_004dcfc5;
          iVar7 = 4;
          pdVar5 = (double *)&DAT_00520928;
        }
        goto LAB_004dcf19;
      }
      local_c = dVar1;
    }
    iVar7 = 3;
    pdVar5 = &local_c;
  }
LAB_004dcf19:
  fVar10 = FUN_004de098(iVar7,&DAT_00520938,&param_1,(undefined8 *)&param_2,*(undefined4 *)pdVar5,
                        *(undefined4 *)((int)pdVar5 + 4));
  return fVar10;
}



/* @004dd070 file=? name=FUN_004dd070 */

undefined4 __cdecl FUN_004dd070(undefined4 *param_1)

{
  uint uVar1;
  undefined4 uVar2;
  uint uVar3;
  
  uVar1 = param_1[1];
  uVar3 = 0;
  if (uVar1 != 0) {
    uVar3 = uVar1 % 10;
    param_1[1] = uVar1 / 10;
  }
  uVar2 = *param_1;
  *param_1 = (int)(CONCAT44(uVar3,uVar2) / 10);
  return (int)(CONCAT44(uVar3,uVar2) % 10);
}



/* @004dd0c8 file=? name=FUN_004dd0c8 */

float10 FUN_004dd0c8(void)

{
  float10 in_ST0;
  
  return ROUND(in_ST0);
}



/* @004dd0f4 file=? name=FUN_004dd0f4 */

void __cdecl FUN_004dd0f4(undefined4 param_1,undefined4 param_2)

{
  if ((param_2._2_2_ & 0x7ff0) < 0x4340) {
    FUN_004dcc1c();
  }
  else {
    FUN_004de098(5,&DAT_00520944,(undefined8 *)&param_1,(undefined8 *)0x0,DAT_0052093c,DAT_00520940)
    ;
  }
  return;
}



/* @004dd138 file=? name=FUN_004dd138 */

float10 __cdecl FUN_004dd138(double param_1)

{
  float10 fVar1;
  
  fVar1 = (float10)param_1;
  if (((ulonglong)param_1 & 0x7fff000000000000) != 0) {
    if ((longlong)param_1 < 0) {
      fVar1 = FUN_004de098(1,&DAT_00520950,&param_1,(undefined8 *)0x0,DAT_00520948,DAT_0052094c);
    }
    else {
      fVar1 = SQRT(fVar1);
    }
  }
  return fVar1;
}



/* @004dd188 file=? name=FUN_004dd188 */

void __cdecl FUN_004dd188(undefined4 param_1,undefined4 param_2)

{
  if ((param_2._2_2_ & 0x7ff0) < 0x4340) {
    FUN_004dcc24();
  }
  else {
    FUN_004de098(5,&DAT_00520960,(undefined8 *)&param_1,(undefined8 *)0x0,DAT_00520958,DAT_0052095c)
    ;
  }
  return;
}



/* @004dd1cc file=? name=FUN_004dd1cc */

void __cdecl FUN_004dd1cc(undefined4 param_1)

{
  FUN_004ddd94(param_1,(undefined4 *)0x0);
  return;
}



/* @004dd1e0 file=? name=FUN_004dd1e0 */

int __cdecl FUN_004dd1e0(char *param_1)

{
  char cVar1;
  int iVar2;
  char *pcVar3;
  bool bVar4;
  
  iVar2 = 0;
  do {
    pcVar3 = param_1;
    cVar1 = *pcVar3;
    param_1 = pcVar3 + 1;
  } while (((&DAT_005207dd)[cVar1] & 1) != 0);
  if ((cVar1 == '+') || (cVar1 == '-')) {
    bVar4 = cVar1 == '-';
    cVar1 = *param_1;
    param_1 = pcVar3 + 2;
  }
  else {
    bVar4 = false;
  }
  while (('/' < cVar1 && (cVar1 < ':'))) {
    iVar2 = iVar2 * 10 + (int)cVar1 + -0x30;
    cVar1 = *param_1;
    param_1 = param_1 + 1;
  }
  if (bVar4) {
    iVar2 = -iVar2;
  }
  return iVar2;
}



/* @004dd23c file=? name=FUN_004dd23c */

void __cdecl FUN_004dd23c(char *param_1)

{
  FUN_004dd1e0(param_1);
  return;
}



/* @004dd24c file=? name=FUN_004dd24c */

void FUN_004dd24c(void)

{
  FUN_004ded48(s_printf___floating_point_formats_n_00520974);
  return;
}



/* @004dd258 file=? name=FUN_004dd258 */

void FUN_004dd258(void)

{
  FUN_004ded48(s_scanf___floating_point_formats_n_0052099f);
  return;
}



/* @004dd264 file=? name=FUN_004dd264 */

float10 __cdecl
FUN_004dd264(int param_1,undefined4 param_2,undefined4 param_3,ushort param_4,undefined4 param_5,
            undefined4 param_6)

{
  ushort uVar1;
  ushort uVar2;
  ushort uVar3;
  float10 fVar4;
  undefined8 local_10;
  
  if (param_1 == 0) {
    uVar1 = 0x407e;
    uVar3 = 0x3f6a;
  }
  else {
    uVar1 = 0x43fe;
    uVar3 = 0x3bcd;
  }
  uVar2 = param_4 & 0x7fff;
  if (uVar2 == 0x7fff) {
    return (float10)CONCAT28(param_4,CONCAT26(param_3._2_2_,CONCAT24((short)param_3,param_2)));
  }
  if (uVar1 < uVar2) {
    local_10 = (double)CONCAT44(param_6,param_5);
  }
  else {
    if (uVar1 == uVar2) {
      FUN_004dc9f8();
      FUN_004dc9f8();
      FUN_004dc9f8();
      return (float10)(float)(float10)CONCAT28(param_4,CONCAT26(param_3._2_2_,
                                                                CONCAT24((short)param_3,param_2)));
    }
    if (((((short)param_2 == 0 && uVar2 == 0) && param_2._2_2_ == 0) && (short)param_3 == 0) &&
        param_3._2_2_ == 0) {
      return (float10)CONCAT28(param_4,CONCAT26(param_3._2_2_,CONCAT24((short)param_3,param_2)));
    }
    if (uVar3 <= uVar2) {
      return (float10)CONCAT28(param_4,CONCAT26(param_3._2_2_,CONCAT24((short)param_3,param_2)));
    }
    local_10 = 0.0;
  }
  DAT_00520bcc = 0x22;
  if ((param_4 & 0x8000) == 0) {
    fVar4 = (float10)local_10;
  }
  else {
    fVar4 = -(float10)local_10;
  }
  return fVar4;
}



/* @004dd35c file=? name=FUN_004dd35c */

char * __cdecl FUN_004dd35c(uint param_1,char *param_2,uint param_3,char param_4,char param_5)

{
  char cVar1;
  char *pcVar2;
  char *pcVar3;
  char local_28 [36];
  
  pcVar3 = param_2;
  if ((1 < (int)param_3) && ((int)param_3 < 0x25)) {
    if (((int)param_1 < 0) && (param_4 != '\0')) {
      *param_2 = '-';
      pcVar3 = param_2 + 1;
      param_1 = -param_1;
    }
    pcVar2 = local_28;
    do {
      *pcVar2 = (char)(param_1 % param_3);
      pcVar2 = pcVar2 + 1;
      param_1 = param_1 / param_3;
    } while (param_1 != 0);
    while (pcVar2 != local_28) {
      pcVar2 = pcVar2 + -1;
      cVar1 = *pcVar2;
      if (cVar1 < '\n') {
        *pcVar3 = cVar1 + '0';
        pcVar3 = pcVar3 + 1;
      }
      else {
        *pcVar3 = cVar1 + param_5 + -10;
        pcVar3 = pcVar3 + 1;
      }
    }
  }
  *pcVar3 = '\0';
  return param_2;
}



/* @004dd3d0 file=? name=FUN_004dd3d0 */

void __cdecl FUN_004dd3d0(uint param_1,char *param_2)

{
  FUN_004dd35c(param_1,param_2,10,'\0','a');
  return;
}



/* @004dd3ec file=? name=FUN_004dd3ec */

void __cdecl FUN_004dd3ec(uint param_1,char *param_2,uint param_3)

{
  FUN_004dd35c(param_1,param_2,param_3,param_3 == 10,'a');
  return;
}



/* @004dd41c file=? name=FUN_004dd41c */

void __cdecl FUN_004dd41c(uint param_1,char *param_2,uint param_3)

{
  FUN_004dd35c(param_1,param_2,param_3,'\0','a');
  return;
}



/* @004dd43c file=? name=FUN_004dd43c */

void __cdecl FUN_004dd43c(uint param_1,char *param_2,uint param_3)

{
  FUN_004dd35c(param_1,param_2,param_3,param_3 == 10,'a');
  return;
}



/* @004dd494 file=? name=FUN_004dd494 */

void __cdecl FUN_004dd494(undefined *param_1,undefined *param_2)

{
  PTR_FUN_005209fc = param_1;
  PTR_LAB_00520a00 = param_2;
  return;
}



/* @004dd4b0 file=? name=FUN_004dd4b0 */

void __cdecl FUN_004dd4b0(uint param_1)

{
  FUN_004de144(param_1);
  return;
}



/* @004dd4c0 file=? name=FUN_004dd4c0 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void __cdecl FUN_004dd4c0(undefined4 param_1)

{
  DAT_00520a48 = param_1;
  _DAT_00520a4c = 0;
  return;
}



/* @004dd4d4 file=? name=FUN_004dd4d4 */

uint FUN_004dd4d4(void)

{
  DAT_00520a48 = DAT_00520a48 * 0x15a4e35 + 1;
  return DAT_00520a48 >> 0x10 & 0x7fff;
}



/* @004dd53c file=? name=FUN_004dd53c */

uint __cdecl FUN_004dd53c(char param_1,uint param_2,uint param_3)

{
  if ((param_1 == 'G') || (param_1 == 'g')) {
    while (*(char *)(param_3 - 1) == '0') {
      param_3 = param_3 - 1;
      if (param_3 <= param_2) {
        return param_2;
      }
    }
  }
  if (*PTR_DAT_005207a0 == *(char *)(param_3 - 1)) {
    param_3 = param_3 - 1;
  }
  return param_3;
}



/* @004dd574 file=? name=FUN_004dd574 */

byte * __cdecl
FUN_004dd574(float10 *param_1,uint param_2,byte *param_3,byte param_4,char param_5,int param_6)

{
  char cVar1;
  int iVar2;
  char *pcVar3;
  byte *pbVar4;
  uint uVar5;
  uint uVar6;
  byte *pbVar7;
  byte *pbVar8;
  int iVar9;
  char *pcVar10;
  byte local_3c [46];
  byte local_e;
  byte local_d;
  uint local_c;
  uint local_8;
  
  local_e = *PTR_DAT_005207a0;
  if (0x28 < (int)param_2) {
    param_2 = 0x28;
  }
  local_c = param_2;
  local_d = param_4 & 0xdf;
  if (local_d == 0x46) {
    uVar5 = -param_2;
    if (0 < (int)-param_2) {
      param_2 = 0;
      uVar5 = 0;
    }
  }
  else if ((int)param_2 < 1) {
    uVar5 = 1;
  }
  else {
    uVar5 = param_2;
    if (local_d == 0x45) {
      uVar5 = param_2 + 1;
      param_2 = param_2 + 1;
    }
  }
  iVar2 = FUN_004dddc8(param_1,uVar5,&local_8,(undefined4 *)local_3c,param_6);
  if (iVar2 == 0x7fff) {
    if (local_8 == 0) {
      pcVar3 = &DAT_00520a55;
    }
    else {
      pcVar3 = &DAT_00520a50;
    }
    uVar5 = 0xffffffff;
    do {
      pcVar10 = pcVar3;
      if (uVar5 == 0) break;
      uVar5 = uVar5 - 1;
      pcVar10 = pcVar3 + 1;
      cVar1 = *pcVar3;
      pcVar3 = pcVar10;
    } while (cVar1 != '\0');
    uVar5 = ~uVar5;
    pbVar7 = (byte *)(pcVar10 + -uVar5);
    pbVar4 = param_3;
    for (uVar6 = uVar5 >> 2; uVar6 != 0; uVar6 = uVar6 - 1) {
      *(undefined4 *)pbVar4 = *(undefined4 *)pbVar7;
      pbVar7 = pbVar7 + 4;
      pbVar4 = pbVar4 + 4;
    }
    for (uVar5 = uVar5 & 3; uVar5 != 0; uVar5 = uVar5 - 1) {
      *pbVar4 = *pbVar7;
      pbVar7 = pbVar7 + 1;
      pbVar4 = pbVar4 + 1;
    }
    return param_3;
  }
  if (iVar2 == 0x7ffe) {
    if (local_8 == 0) {
      pcVar3 = &DAT_00520a5f;
    }
    else {
      pcVar3 = &DAT_00520a5a;
    }
    uVar5 = 0xffffffff;
    do {
      pcVar10 = pcVar3;
      if (uVar5 == 0) break;
      uVar5 = uVar5 - 1;
      pcVar10 = pcVar3 + 1;
      cVar1 = *pcVar3;
      pcVar3 = pcVar10;
    } while (cVar1 != '\0');
    uVar5 = ~uVar5;
    pbVar7 = (byte *)(pcVar10 + -uVar5);
    pbVar4 = param_3;
    for (uVar6 = uVar5 >> 2; uVar6 != 0; uVar6 = uVar6 - 1) {
      *(undefined4 *)pbVar4 = *(undefined4 *)pbVar7;
      pbVar7 = pbVar7 + 4;
      pbVar4 = pbVar4 + 4;
    }
    for (uVar5 = uVar5 & 3; uVar5 != 0; uVar5 = uVar5 - 1) {
      *pbVar4 = *pbVar7;
      pbVar7 = pbVar7 + 1;
      pbVar4 = pbVar4 + 1;
    }
    return param_3;
  }
  pbVar7 = param_3;
  if (local_8 != 0) {
    *param_3 = 0x2d;
    pbVar7 = param_3 + 1;
  }
  if (local_d != 0x46) {
    if ((local_d != 0x47) || (iVar2 < -3)) goto LAB_004dd739;
    uVar5 = param_2;
    if (param_2 == 0) {
      uVar5 = 1;
    }
    if ((int)uVar5 < iVar2) goto LAB_004dd739;
  }
  if (iVar2 < 0x29) {
    if (iVar2 < 1) {
      *pbVar7 = 0x30;
      pbVar7[1] = local_e;
      pbVar7 = pbVar7 + 2;
      for (iVar9 = iVar2; iVar2 = 0, iVar9 != 0; iVar9 = iVar9 + 1) {
        *pbVar7 = 0x30;
        pbVar7 = pbVar7 + 1;
      }
    }
    iVar9 = 0;
    for (pbVar4 = local_3c; *pbVar4 != 0; pbVar4 = pbVar4 + 1) {
      *pbVar7 = *pbVar4;
      pbVar8 = pbVar7 + 1;
      iVar2 = iVar2 + -1;
      if (iVar2 == 0) {
        *pbVar8 = local_e;
        pbVar8 = pbVar7 + 2;
        iVar9 = iVar9 + 1;
      }
      pbVar7 = pbVar8;
    }
    if ((int)(iVar9 + local_c) < (int)param_2) {
      uVar5 = param_2 - (iVar9 + local_c);
      pbVar4 = (byte *)FUN_004d4988((undefined4 *)pbVar7,0x30,uVar5);
      pbVar7 = pbVar7 + uVar5;
    }
    else if ((iVar2 != 1) && (param_5 == '\0')) {
      pbVar4 = (byte *)FUN_004dd53c(param_4,(uint)param_3,(uint)pbVar7);
      pbVar7 = pbVar4;
    }
    if (pbVar7 == param_3) {
      *pbVar7 = 0x30;
      pbVar7 = pbVar7 + 1;
    }
    *pbVar7 = 0;
    return pbVar4;
  }
LAB_004dd739:
  *pbVar7 = local_3c[0];
  pbVar4 = pbVar7 + 1;
  if (local_3c[1] == 0) {
    if (param_5 != '\0') {
      *pbVar4 = local_e;
      pbVar4 = pbVar7 + 2;
    }
  }
  else {
    *pbVar4 = local_e;
    pbVar4 = pbVar7 + 2;
    pbVar7 = local_3c + 2;
    while (local_3c[1] != 0) {
      *pbVar4 = local_3c[1];
      pbVar4 = pbVar4 + 1;
      local_3c[1] = *pbVar7;
      pbVar7 = pbVar7 + 1;
    }
    if (param_5 == '\0') {
      pbVar4 = (byte *)FUN_004dd53c(param_4,(uint)param_3,(uint)pbVar4);
    }
  }
  *pbVar4 = param_4 & 0x20 | 0x45;
  pbVar7 = (byte *)(iVar2 + -1);
  if ((int)pbVar7 < 0) {
    pbVar7 = (byte *)-(int)pbVar7;
    pbVar4[1] = 0x2d;
  }
  else {
    pbVar4[1] = 0x2b;
  }
  if ((int)pbVar7 < 1000) {
    if ((int)pbVar7 < 100) {
      iVar2 = 2;
    }
    else {
      iVar2 = 3;
    }
  }
  else {
    iVar2 = 4;
  }
  pbVar4[iVar2 + 2] = 0;
  pbVar4 = pbVar4 + iVar2 + 2;
  pbVar8 = pbVar4;
  for (; iVar2 != 0; iVar2 = iVar2 + -1) {
    pbVar4 = pbVar4 + -1;
    *pbVar4 = (char)((int)pbVar7 % 10) + 0x30;
    pbVar8 = (byte *)((int)pbVar7 / 10);
    pbVar7 = pbVar8;
  }
  return pbVar8;
}



/* @004dd7f4 file=? name=FUN_004dd7f4 */

int __cdecl FUN_004dd7f4(int param_1,int param_2)

{
  int iVar1;
  
  if (param_2 == 0) {
    iVar1 = param_1 + 8;
  }
  else {
    iVar1 = param_1 + 0xc;
  }
  return iVar1;
}



/* @004ddc7c file=? name=FUN_004ddc7c */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void __cdecl FUN_004ddc7c(float *param_1,double *param_2,uint param_3)

{
  float10 fVar1;
  
  if ((param_3 & 4) == 0) {
    if ((param_3 & 8) == 0) {
      fVar1 = FUN_004dd264(0,*param_1,param_1[1],SUB42(param_1[2],0),SUB84((double)_DAT_00520a64,0),
                           (int)((ulonglong)(double)_DAT_00520a64 >> 0x20));
      *(float *)param_2 = (float)fVar1;
    }
    else {
      *(float *)param_2 = *param_1;
      *(float *)((int)param_2 + 4) = param_1[1];
      *(undefined2 *)(param_2 + 1) = *(undefined2 *)(param_1 + 2);
    }
  }
  else {
    fVar1 = FUN_004dd264(1,*param_1,param_1[1],SUB42(param_1[2],0),DAT_005209d4,DAT_005209d8);
    *param_2 = (double)fVar1;
  }
  return;
}



/* @004ddd20 file=? name=FUN_004ddd20 */

void __cdecl FUN_004ddd20(undefined4 param_1,int *param_2)

{
  *param_2 = *param_2 + -1;
  return;
}



/* @004ddd2c file=? name=FUN_004ddd2c */

undefined1  [10] __cdecl FUN_004ddd2c(undefined4 param_1,undefined4 *param_2)

{
  undefined1 local_18 [10];
  int local_c;
  
  thunk_FUN_004dd258();
  if ((0 < local_c) && (local_c == 2)) {
    DAT_00520bcc = 0x22;
  }
  if (param_2 != (undefined4 *)0x0) {
    *param_2 = param_1;
  }
  return local_18;
}



/* @004ddd94 file=? name=FUN_004ddd94 */

void __cdecl FUN_004ddd94(undefined4 param_1,undefined4 *param_2)

{
  undefined1 auVar1 [10];
  undefined4 uVar2;
  undefined4 uVar3;
  
  uVar2 = DAT_005209d4;
  uVar3 = DAT_005209d8;
  auVar1 = FUN_004ddd2c(param_1,param_2);
  FUN_004dd264(1,auVar1._0_4_,auVar1._4_4_,auVar1._8_2_,uVar2,uVar3);
  return;
}



/* @004dddc8 file=? name=FUN_004dddc8 */

/* WARNING: Restarted to delay deadcode elimination for space: stack */

int __cdecl
FUN_004dddc8(float10 *param_1,uint param_2,uint *param_3,undefined4 *param_4,int param_5)

{
  ushort uVar1;
  uint uVar2;
  undefined4 uVar3;
  uint uVar4;
  char *pcVar5;
  byte bVar6;
  uint uVar7;
  float10 fVar8;
  undefined4 *local_28;
  int local_18;
  undefined1 local_10 [8];
  ushort uStack_8;
  short local_6;
  
  local_6 = 10;
  if (param_5 == 2) {
    _local_10 = (float10)*(float *)param_1;
  }
  else if (param_5 == 6) {
    _local_10 = (float10)*(double *)param_1;
  }
  else if (param_5 == 8) {
    _local_10 = *param_1;
  }
  uVar1 = uStack_8;
  uVar2 = (uint)uStack_8;
  _local_10 = (float10)CONCAT28(uStack_8 & 0x7fff,local_10);
  *param_3 = (uint)((uVar1 & 0x8000) != 0);
  uVar1 = FUN_004dce10((float10 *)local_10);
  uVar1 = uVar1 & 0x4700;
  if (uVar1 != 0x4000) {
    if (uVar1 == 0x500) {
      return 0x7fff;
    }
    if (uVar1 == 0x100) {
      return 0x7ffe;
    }
    uVar2 = ((uVar2 & 0x7fff) - 0x3fff) * 0x4d10 + ((uint)local_10[7] * 2 & 0xff) * 0x4d;
    local_18 = (int)uVar2 >> 0x10;
    if ((uVar2 & 0xffff) != 0) {
      local_18 = local_18 + 1;
    }
    uVar2 = param_2;
    if ((0 < (int)param_2) || (uVar2 = local_18 - param_2, -1 < (int)uVar2)) {
      if (0x13 < (int)uVar2) {
        uVar2 = 0x13;
      }
      for (uVar7 = uVar2 - local_18; uVar7 != 0; uVar7 = uVar7 + uVar4) {
        uVar4 = uVar7;
        if ((int)uVar7 < 0) {
          uVar4 = -uVar7;
        }
        if (0x1344 < (int)uVar4) {
          uVar4 = 0x1344;
        }
        fVar8 = FUN_004de144(uVar4);
        if ((int)uVar7 < 0) {
          _local_10 = _local_10 / fVar8;
        }
        else {
          _local_10 = _local_10 * fVar8;
          uVar4 = -uVar4;
        }
      }
      fVar8 = FUN_004de144(uVar2);
      if (_local_10 <= fVar8) {
        fVar8 = FUN_004de144(uVar2 - 1);
        uVar7 = uVar2;
        if (_local_10 < fVar8) {
          local_18 = local_18 + -1;
          uVar7 = uVar2 - 1;
          if (0 < (int)param_2) {
            _local_10 = _local_10 * (float10)(int)local_6;
            uVar7 = uVar2;
          }
        }
      }
      else {
        local_18 = local_18 + 1;
        uVar7 = uVar2 + 1;
        if (((int)uVar7 < 0x14) && (0 < (int)param_2)) {
          _local_10 = _local_10 / (float10)(int)local_6;
          uVar7 = uVar2;
        }
      }
      if (-1 < (int)uVar7) {
        FUN_004dcdec((longlong *)local_10,(float10 *)local_10);
        local_28 = (undefined4 *)((int)param_4 + uVar7);
        *(undefined1 *)local_28 = 0;
        pcVar5 = (char *)((int)local_28 + -1);
        bVar6 = 0;
        if (uVar7 == 0) {
          if (local_10[0] != '\x01') goto LAB_004dde4f;
          bVar6 = 0;
        }
        else {
          do {
            uVar3 = FUN_004dd070((undefined4 *)local_10);
            bVar6 = bVar6 | (byte)uVar3;
            *pcVar5 = (byte)uVar3 + 0x30;
            pcVar5 = pcVar5 + -1;
            uVar7 = uVar7 - 1;
          } while (uVar7 != 0);
        }
        if (bVar6 == 0) {
          local_18 = local_18 + 1;
          if ((int)param_2 < 1) {
            *(undefined1 *)local_28 = 0x30;
          }
          local_28 = (undefined4 *)((int)local_28 + 1);
          pcVar5[1] = '1';
        }
        if ((int)param_2 < 1) {
          param_2 = local_18 - param_2;
        }
        if (0x28 < (int)param_2) {
          param_2 = 0x28;
        }
        *(undefined1 *)local_28 = 0;
        uVar2 = param_2 - ((int)local_28 - (int)param_4);
        if ((int)uVar2 < 1) {
          return local_18;
        }
        FUN_004d4988(local_28,0x30,uVar2);
        *(undefined1 *)((int)local_28 + uVar2) = 0;
        return local_18;
      }
    }
  }
LAB_004dde4f:
  if ((int)param_2 < 1) {
    param_2 = 1 - param_2;
  }
  if (0x28 < (int)param_2) {
    param_2 = 0x28;
  }
  FUN_004d4988(param_4,0x30,param_2);
  *(undefined1 *)((int)param_4 + param_2) = 0;
  *param_3 = 0;
  return 1;
}



/* @004de098 file=? name=FUN_004de098 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

float10 __cdecl
FUN_004de098(int param_1,undefined4 param_2,undefined8 *param_3,undefined8 *param_4,
            undefined4 param_5,undefined4 param_6)

{
  int iVar1;
  char local_74 [80];
  int local_24;
  undefined4 local_20;
  undefined8 local_1c;
  undefined8 local_14;
  undefined4 local_c;
  undefined4 uStack_8;
  
  local_24 = param_1;
  local_20 = param_2;
  local_1c = _DAT_004de13c;
  if (param_3 != (undefined8 *)0x0) {
    local_1c = *param_3;
  }
  local_14 = _DAT_004de13c;
  if (param_4 != (undefined8 *)0x0) {
    local_14 = *param_4;
  }
  local_c = param_5;
  uStack_8 = param_6;
  iVar1 = (*(code *)PTR_FUN_005209fc)(&local_24);
  if (iVar1 == 0) {
    FUN_004d7f10(local_74,s__s___s_error_00520a8c);
    if (param_1 - 2U < 3) {
      DAT_00520bcc = 0x22;
    }
    else {
      DAT_00520bcc = 0x21;
    }
    FUN_004dec88(local_74);
  }
  return (float10)(double)CONCAT44(uStack_8,local_c);
}



/* @004de144 file=? name=FUN_004de144 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

float10 __cdecl FUN_004de144(uint param_1)

{
  uint uVar1;
  uint uVar2;
  undefined1 local_10 [8];
  undefined2 uStack_8;
  
  _local_10 = _DAT_004de2a0;
  if (((-0x1345 < (int)param_1) && (_local_10 = _DAT_00520b52, (int)param_1 < 0x1345)) &&
     (_local_10 = _DAT_004de2ac, param_1 != 0)) {
    uVar1 = param_1;
    if ((int)param_1 < 0) {
      uVar1 = -param_1;
    }
    uVar2 = uVar1 & 7;
    _local_10 = (float10)CONCAT28(*(undefined2 *)(&DAT_00520aa4 + uVar2 * 10),
                                  CONCAT44(*(undefined4 *)(&DAT_00520aa0 + uVar2 * 10),
                                           *(undefined4 *)(&DAT_00520a9c + uVar2 * 10)));
    if (((int)uVar1 >> 3 & 1U) != 0) {
      _local_10 = _local_10 * _DAT_00520aec;
    }
    if ((int)uVar1 >> 4 != 0) {
      if (((int)uVar1 >> 4 & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520af8;
      }
      if (((int)uVar1 >> 5 & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b02;
      }
      if (((int)uVar1 >> 6 & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b0c;
      }
      if (((int)uVar1 >> 7 & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b16;
      }
      if (((int)uVar1 >> 8 & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b20;
      }
      if (((int)uVar1 >> 9 & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b2a;
      }
      if (((int)uVar1 >> 10 & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b34;
      }
      if (((int)uVar1 >> 0xb & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b3e;
      }
      if (((int)uVar1 >> 0xc & 1U) != 0) {
        _local_10 = _local_10 * _DAT_00520b48;
      }
    }
    if ((int)param_1 < 0) {
      _local_10 = (float10)_DAT_004de2b8 / _local_10;
    }
  }
  return _local_10;
}



/* @004de2bc file=? name=FUN_004de2bc */

int * __cdecl FUN_004de2bc(int param_1,int param_2)

{
  int *piVar1;
  
  piVar1 = FUN_004de55c(param_1 * param_2);
  if (piVar1 != (int *)0x0) {
    FUN_004d4988(piVar1,0,param_1 * param_2);
  }
  return piVar1;
}



/* @004de2e8 file=? name=FUN_004de2e8 */

undefined4 __cdecl FUN_004de2e8(int param_1)

{
  int iVar1;
  uint uVar2;
  uint uVar3;
  uint local_c;
  int *local_8;
  
  uVar2 = param_1 + 0xffffU & 0xffff0000;
  uVar3 = (int)DAT_00520b60 - (int)DAT_00520b5c;
  if (uVar3 != 0) {
    if (uVar2 < uVar3) {
      uVar3 = uVar2;
    }
    iVar1 = FUN_004deac8(DAT_00520b5c,uVar3);
    if (iVar1 == 0) {
      return 0xffffffff;
    }
    FUN_004de4b8(DAT_00520b5c,uVar3);
    DAT_00520b5c = (int *)((int)DAT_00520b5c + uVar3);
  }
  if (uVar3 < uVar2) {
    iVar1 = FUN_004dea5c(uVar2,&local_8,&local_c);
    if (iVar1 == 0) {
      return 0xffffffff;
    }
    if (local_8 == DAT_00520b60) {
      uVar2 = uVar2 - uVar3;
    }
    iVar1 = FUN_004deac8(local_8,uVar2);
    if (iVar1 == 0) {
      FUN_004deb5c(local_8);
      return 0xffffffff;
    }
    FUN_004de4b8(local_8,uVar2);
    DAT_00520b5c = (int *)(uVar2 + (int)local_8);
    DAT_00520b60 = (int *)((int)local_8 + local_c);
  }
  return 0;
}



/* @004de420 file=? name=FUN_004de420 */

void __cdecl FUN_004de420(int *param_1)

{
  uint uVar1;
  int *piVar2;
  int iVar3;
  undefined4 *puVar4;
  uint uVar5;
  int *piVar6;
  bool bVar7;
  
  if ((param_1 != (int *)0x0) && ((param_1[-1] & 1U) != 0)) {
    uVar5 = param_1[-1] & 0xfffffffe;
    uVar1 = param_1[-2];
    bVar7 = (uVar1 & 1) == 0;
    if (bVar7) {
      param_1 = (int *)((int)param_1 - uVar1);
      uVar5 = uVar5 + uVar1;
    }
    piVar6 = (int *)(uVar5 + (int)param_1);
    uVar1 = piVar6[-1];
    if ((uVar1 & 1) == 0) {
      piVar2 = (int *)piVar6[1];
      iVar3 = *piVar6;
      *piVar2 = iVar3;
      *(int *)(iVar3 + 4) = piVar6[1];
      if (piVar6 == DAT_00525120) {
        DAT_00525120 = piVar2;
      }
      uVar5 = uVar5 + uVar1;
    }
    *(uint *)((int)param_1 + (uVar5 - 8)) = uVar5;
    param_1[-1] = uVar5;
    if (!bVar7) {
      puVar4 = *(undefined4 **)(DAT_0052511c + 4);
      *(int **)(DAT_0052511c + 4) = param_1;
      param_1[1] = (int)puVar4;
      *param_1 = DAT_0052511c;
      *puVar4 = param_1;
    }
  }
  return;
}



/* @004de4b8 file=? name=FUN_004de4b8 */

undefined4 __cdecl FUN_004de4b8(int *param_1,uint param_2)

{
  undefined4 uVar1;
  int *piVar2;
  int iVar3;
  uint uVar4;
  
  if (param_2 < 0x10) {
    uVar1 = 0xffffffff;
  }
  else {
    uVar4 = param_2 & 0xfffffffc;
    iVar3 = 0;
    for (piVar2 = &DAT_00524f08; (iVar3 < DAT_00525108 && ((int *)(*piVar2 + piVar2[1]) != param_1))
        ; piVar2 = piVar2 + 2) {
      iVar3 = iVar3 + 1;
    }
    if (iVar3 == DAT_00525108) {
      if (DAT_00525108 == 0x40) {
        return 0xffffffff;
      }
      (&DAT_00524f08)[DAT_00525108 * 2] = param_1;
      (&DAT_00524f0c)[DAT_00525108 * 2] = uVar4;
      DAT_00525108 = DAT_00525108 + 1;
      uVar4 = uVar4 - 8;
      piVar2 = param_1 + 2;
      *param_1 = 1;
    }
    else {
      (&DAT_00524f0c)[iVar3 * 2] = (&DAT_00524f0c)[iVar3 * 2] + uVar4;
      piVar2 = param_1;
    }
    piVar2[-1] = uVar4 | 1;
    *(uint *)((int)piVar2 + (uVar4 - 8)) = uVar4 | 1;
    *(undefined4 *)((int)piVar2 + (uVar4 - 4)) = 1;
    FUN_004de420(piVar2);
    uVar1 = 0;
  }
  return uVar1;
}



/* @004de55c file=? name=FUN_004de55c */

int * __cdecl FUN_004de55c(uint param_1)

{
  uint uVar1;
  int *piVar2;
  int *piVar3;
  int iVar4;
  int *piVar5;
  int iVar6;
  uint uVar7;
  uint uVar8;
  
  if (param_1 < 8) {
    uVar8 = 0x10;
  }
  else {
    uVar8 = (param_1 + 3 & 0xfffffffc) + 8;
  }
  if ((0xf < (int)uVar8) && (param_1 != 0)) {
    iVar6 = 0;
    piVar3 = DAT_00525120;
    do {
      do {
        uVar1 = piVar3[-1];
        if (uVar8 <= uVar1) {
          iVar6 = *piVar3;
          piVar2 = (int *)piVar3[1];
          uVar7 = uVar1 - uVar8;
          if (0xf < uVar7) {
            piVar5 = (int *)(uVar8 + (int)piVar3);
            *(int **)(iVar6 + 4) = piVar5;
            DAT_00525120 = piVar5;
            *piVar2 = (int)piVar5;
            piVar5[1] = (int)piVar2;
            *piVar5 = iVar6;
            piVar5[-2] = uVar8 | 1;
            piVar3[-1] = uVar8 | 1;
            *(uint *)((int)piVar5 + (uVar7 - 8)) = uVar7;
            piVar5[-1] = uVar7;
            return piVar3;
          }
          *(int **)(iVar6 + 4) = piVar2;
          *piVar2 = iVar6;
          if (piVar3 == DAT_00525120) {
            DAT_00525120 = piVar2;
          }
          *(uint *)((int)piVar3 + (uVar1 - 8)) = uVar1 | 1;
          piVar3[-1] = uVar1 | 1;
          return piVar3;
        }
        piVar2 = piVar3 + 1;
        piVar3 = (int *)*piVar2;
      } while ((int *)*piVar2 != DAT_00525120);
      if (iVar6 == 2) {
        return (int *)0x0;
      }
      iVar6 = iVar6 + 1;
      iVar4 = FUN_004de2e8(uVar8);
      piVar3 = DAT_00525120;
    } while (iVar4 == 0);
  }
  return (int *)0x0;
}



/* @004de644 file=? name=FUN_004de644 */

int __cdecl FUN_004de644(int param_1,uint param_2)

{
  int iVar1;
  uint uVar2;
  uint uVar3;
  uint uVar4;
  int *piVar5;
  int *piVar6;
  
  if (param_2 < 8) {
    uVar2 = 0x10;
  }
  else {
    uVar2 = (param_2 + 3 & 0xfffffffc) + 8;
  }
  if (((int)uVar2 < 0x10) || (param_2 == 0)) {
    param_1 = 0;
  }
  else {
    uVar4 = *(uint *)(param_1 + -4) & 0xfffffffe;
    if (uVar2 != uVar4) {
      if (uVar4 < uVar2) {
        piVar5 = (int *)(param_1 + uVar4);
        uVar3 = piVar5[-1];
        if (((uVar3 & 1) == 0) && (uVar2 <= uVar4 + uVar3)) {
          iVar1 = *piVar5;
          if (piVar5 == DAT_00525120) {
            piVar5 = (int *)piVar5[1];
            DAT_00525120 = piVar5;
          }
          else {
            piVar5 = (int *)piVar5[1];
          }
          uVar4 = (uVar4 + uVar3) - uVar2;
          if (uVar4 < 0x10) {
            *(int **)(iVar1 + 4) = piVar5;
            *piVar5 = iVar1;
            uVar3 = uVar2 + uVar4 | 1;
            *(uint *)(param_1 + uVar2 + uVar4 + -8) = uVar3;
            *(uint *)(param_1 + -4) = uVar3;
          }
          else {
            piVar6 = (int *)(param_1 + uVar2);
            *(int **)(iVar1 + 4) = piVar6;
            *piVar5 = (int)piVar6;
            piVar6[1] = (int)piVar5;
            *piVar6 = iVar1;
            piVar6[-2] = uVar2 | 1;
            *(uint *)(param_1 + -4) = uVar2 | 1;
            *(uint *)((int)piVar6 + (uVar4 - 8)) = uVar4;
            piVar6[-1] = uVar4;
          }
        }
        else {
          param_1 = 0;
        }
      }
      else {
        uVar4 = uVar4 - uVar2;
        if (0xf < uVar4) {
          piVar5 = (int *)(param_1 + uVar2);
          piVar5[-2] = uVar2 | 1;
          *(uint *)(param_1 + -4) = uVar2 | 1;
          *(uint *)((int)piVar5 + (uVar4 - 8)) = uVar4 | 1;
          piVar5[-1] = uVar4 | 1;
          FUN_004de420(piVar5);
        }
      }
    }
  }
  return param_1;
}



/* @004de760 file=? name=FUN_004de760 */

int * __cdecl FUN_004de760(int *param_1,uint param_2)

{
  int *piVar1;
  int iVar2;
  uint uVar3;
  int *piVar4;
  uint uVar5;
  uint local_c;
  
  if (param_2 == 0) {
    FUN_004de420(param_1);
    piVar1 = (int *)0x0;
  }
  else if (param_1 == (int *)0x0) {
    piVar1 = FUN_004de55c(param_2);
  }
  else {
    iVar2 = FUN_004de644((int)param_1,param_2);
    piVar1 = param_1;
    if (iVar2 == 0) {
      if (param_2 < 8) {
        local_c = 0x10;
      }
      else {
        local_c = (param_2 + 3 & 0xfffffffc) + 8;
      }
      if (((int)local_c < 0x10) || (param_2 == 0)) {
        piVar1 = (int *)0x0;
      }
      else {
        uVar5 = param_1[-1] & 0xfffffffe;
        uVar3 = param_1[-2];
        if (((uVar3 & 1) == 0) && (local_c <= uVar3 + uVar5)) {
          piVar1 = (int *)((int)param_1 - uVar3);
          piVar4 = (int *)piVar1[1];
          iVar2 = *piVar1;
          *(int **)(iVar2 + 4) = piVar4;
          *piVar4 = iVar2;
          if (piVar1 == DAT_00525120) {
            DAT_00525120 = piVar4;
          }
          FUN_004d493c(piVar1,param_1,uVar5);
          uVar5 = uVar5 + uVar3;
          uVar3 = uVar5 - local_c;
          if (uVar3 < 0x10) {
            *(uint *)((int)piVar1 + (uVar5 - 8)) = uVar5 | 1;
            piVar1[-1] = uVar5 | 1;
          }
          else {
            piVar4 = (int *)(local_c + (int)piVar1);
            piVar4[-2] = local_c | 1;
            piVar1[-1] = local_c | 1;
            *(uint *)((int)piVar4 + (uVar3 - 8)) = uVar3 | 1;
            piVar4[-1] = uVar3 | 1;
            FUN_004de420(piVar4);
          }
        }
        else {
          piVar1 = FUN_004de55c(param_2);
          if (piVar1 != (int *)0x0) {
            FUN_004d493c(piVar1,param_1,uVar5 - 8);
            FUN_004de420(param_1);
          }
        }
      }
    }
  }
  return piVar1;
}



/* @004de8b8 file=? name=FUN_004de8b8 */

int __cdecl FUN_004de8b8(int param_1)

{
  if (param_1 == 0) {
    return 0;
  }
  return (*(uint *)(param_1 + -4) & 0xfffffffe) - 8;
}



/* @004de8d4 file=? name=FUN_004de8d4 */

int * __cdecl FUN_004de8d4(int *param_1,int param_2,int param_3,uint param_4,undefined *param_5)

{
  int *piVar1;
  uint uVar2;
  
  if (param_1 == (int *)0x0) {
    param_1 = (int *)0x0;
  }
  else {
    if ((param_4 & 0x10) != 0) {
      param_3 = param_1[-1];
    }
    uVar2 = param_4 & 7;
    piVar1 = (int *)((param_3 + -1) * param_2 + (int)param_1);
    while (param_3 != 0) {
      if (uVar2 == 1) {
        (*(code *)param_5)(piVar1,2);
      }
      else if (uVar2 == 2) {
        (*(code *)param_5)(piVar1,2);
      }
      else if (uVar2 == 3) {
        (*(code *)param_5)();
      }
      else if (uVar2 == 5) {
        (*(code *)param_5)(piVar1,2);
      }
      else {
        FUN_004ded48(s_Illegal_mode_in__vector_delete__00520b64);
      }
      piVar1 = (int *)((int)piVar1 - param_2);
      param_3 = param_3 + -1;
    }
    if ((param_4 & 0x10) != 0) {
      param_1 = param_1 + -1;
    }
    if ((param_4 & 8) != 0) {
      FUN_004022e8(param_1);
      param_1 = (int *)0x0;
    }
  }
  return param_1;
}



/* @004de998 file=? name=FUN_004de998 */

int * __cdecl FUN_004de998(int *param_1,int param_2,int param_3,uint param_4,undefined *param_5)

{
  undefined4 uVar1;
  uint uVar2;
  int iVar3;
  int *unaff_EDI;
  
  uVar1 = *DAT_00524c68;
  if (param_1 == (int *)0x0) {
    iVar3 = 4;
    if ((param_4 & 0x10) == 0) {
      iVar3 = 0;
    }
    param_1 = (int *)FUN_004022b0(param_2 * param_3 + iVar3);
    if (param_1 == (int *)0x0) {
      return unaff_EDI;
    }
  }
  if ((param_4 & 0x10) != 0) {
    *param_1 = param_3;
    param_1 = param_1 + 1;
  }
  if (param_5 != (undefined *)0x0) {
    while (param_3 != 0) {
      uVar2 = param_4 & 7;
      if (uVar2 == 1) {
        (*(code *)param_5)(param_1);
      }
      else if (uVar2 == 2) {
        (*(code *)param_5)(param_1);
      }
      else if (uVar2 == 3) {
        (*(code *)param_5)();
      }
      else if (uVar2 == 5) {
        (*(code *)param_5)(param_1);
      }
      else {
        FUN_004ded48(s_Illegal_mode_in__vector_new__00520b84);
      }
      param_1 = (int *)((int)param_1 + param_2);
      param_3 = param_3 + -1;
    }
    if ((param_4 & 0x200) != 0) {
      *DAT_00524c68 = uVar1;
    }
  }
  return unaff_EDI;
}



/* @004dea5c file=? name=FUN_004dea5c */

undefined4 __cdecl FUN_004dea5c(int param_1,undefined4 *param_2,uint *param_3)

{
  LPVOID pvVar1;
  uint dwSize;
  
  if (DAT_00520ba4 == 0) {
    if ((DAT_00525224 == 1) || (DAT_00525224 == 2)) {
      DAT_00520ba4 = 0x100000;
    }
    else {
      DAT_00520ba4 = 0x400000;
    }
  }
  dwSize = (param_1 + DAT_00520ba4) - 1U & ~(DAT_00520ba4 - 1U);
  pvVar1 = VirtualAlloc((LPVOID)0x0,dwSize,0x2000,1);
  *param_2 = pvVar1;
  if (pvVar1 == (LPVOID)0x0) {
    return 0;
  }
  *param_3 = dwSize;
  return 1;
}



/* @004deac8 file=? name=FUN_004deac8 */

undefined4 __cdecl FUN_004deac8(LPVOID param_1,int param_2)

{
  LPVOID pvVar1;
  LPVOID lpAddress;
  
  lpAddress = param_1;
  while( true ) {
    if (param_2 == 0) {
      return 1;
    }
    pvVar1 = VirtualAlloc(lpAddress,0x1000,0x1000,4);
    if (pvVar1 == (LPVOID)0x0) break;
    lpAddress = (LPVOID)((int)lpAddress + 0x1000);
    param_2 = param_2 + -0x1000;
  }
  FUN_004deb1c(param_1,(int)lpAddress - (int)param_1);
  return 0;
}



/* @004deb1c file=? name=FUN_004deb1c */

undefined4 __cdecl FUN_004deb1c(LPVOID param_1,int param_2)

{
  BOOL BVar1;
  
  while( true ) {
    if (param_2 == 0) {
      return 1;
    }
    BVar1 = VirtualFree(param_1,0x1000,0x4000);
    if (BVar1 != 1) break;
    param_1 = (LPVOID)((int)param_1 + 0x1000);
    param_2 = param_2 + -0x1000;
  }
  return 0;
}



/* @004deb5c file=? name=FUN_004deb5c */

undefined4 __cdecl FUN_004deb5c(LPVOID param_1)

{
  BOOL BVar1;
  
  BVar1 = VirtualFree(param_1,0,0x8000);
  if (BVar1 != 1) {
    return 0;
  }
  return 1;
}



/* @004deb80 file=? name=FUN_004deb80 */

void __cdecl FUN_004deb80(char *param_1,int param_2)

{
  char *pcVar1;
  int iVar2;
  uint uVar3;
  undefined4 *local_8;
  
  *param_1 = '\0';
  local_8 = (undefined4 *)&stack0x0000000c;
  while( true ) {
    pcVar1 = (char *)*local_8;
    if (pcVar1 == (char *)0x0) {
      return;
    }
    iVar2 = FUN_004d4a78(param_1);
    uVar3 = (param_2 - iVar2) - 1;
    if ((int)uVar3 < 1) break;
    FUN_004d4a94(param_1,pcVar1,uVar3);
    local_8 = local_8 + 1;
  }
  return;
}



/* @004debc8 file=? name=FUN_004debc8 */

void __cdecl FUN_004debc8(undefined4 param_1,undefined4 param_2,uint param_3)

{
  int iVar1;
  
  FUN_004deb80(&DAT_00525124,0xf6);
  iVar1 = FUN_004d4a78(&DAT_00525124);
  FUN_004dd3d0(param_3,&DAT_00525124 + iVar1);
  FUN_004dec88(&DAT_00525124);
  FUN_004dedb8();
  return;
}



/* @004dec40 file=? name=FUN_004dec40 */

undefined4 FUN_004dec40(void)

{
  DWORD DVar1;
  undefined4 uVar2;
  WNDENUMPROC lpfn;
  int *lParam;
  int local_4;
  
  lParam = &local_4;
  local_4 = 0;
  DVar1 = GetVersion();
  if ((DVar1 & 0x80000000) == 0) {
    return 0x2000;
  }
  lpfn = (WNDENUMPROC)&LAB_004dec2c;
  DVar1 = GetCurrentThreadId();
  EnumThreadWindows(DVar1,lpfn,(LPARAM)lParam);
  uVar2 = 0x2000;
  if (local_4 == 0) {
    uVar2 = 0x1000;
  }
  return uVar2;
}



/* @004dec88 file=? name=FUN_004dec88 */

void __cdecl FUN_004dec88(char *param_1)

{
  char *pcVar1;
  uint uVar2;
  HANDLE hFile;
  DWORD nNumberOfBytesToWrite;
  LPCSTR lpCaption;
  DWORD *lpNumberOfBytesWritten;
  LPOVERLAPPED lpOverlapped;
  CHAR local_58 [80];
  DWORD local_8;
  
  if (DAT_004e0069 != '\0') {
    GetModuleFileNameA((HMODULE)0x0,local_58,0x50);
    pcVar1 = FUN_004d4c4c(local_58,'\\');
    if ((pcVar1 == (char *)0x0) && (pcVar1 = FUN_004d4c4c(local_58,':'), pcVar1 == (char *)0x0)) {
      lpCaption = local_58;
    }
    else {
      lpCaption = pcVar1 + 1;
    }
    uVar2 = FUN_004dec40();
    MessageBoxA((HWND)0x0,param_1,lpCaption,uVar2 | 0x10);
    return;
  }
  hFile = GetStdHandle(0xfffffff4);
  WriteFile(hFile,&DAT_00520bd0,2,&local_8,(LPOVERLAPPED)0x0);
  lpOverlapped = (LPOVERLAPPED)0x0;
  lpNumberOfBytesWritten = &local_8;
  nNumberOfBytesToWrite = FUN_004d4a78(param_1);
  WriteFile(hFile,param_1,nNumberOfBytesToWrite,lpNumberOfBytesWritten,lpOverlapped);
  WriteFile(hFile,&DAT_00520bd3,2,&local_8,(LPOVERLAPPED)0x0);
  return;
}



/* @004ded38 file=? name=FUN_004ded38 */

void __cdecl FUN_004ded38(char *param_1)

{
  FUN_004dec88(param_1);
  return;
}



/* @004ded48 file=? name=FUN_004ded48 */

void __cdecl FUN_004ded48(char *param_1)

{
  FUN_004dec88(param_1);
  FUN_004dee3c(1);
  return;
}



/* @004deda4 file=? name=FUN_004deda4 */

void FUN_004deda4(void)

{
  FUN_004dec88(s_Abnormal_program_termination_00520bf0);
  FUN_004dee3c(3);
  return;
}



/* @004dedb8 file=? name=FUN_004dedb8 */

void FUN_004dedb8(void)

{
  FUN_004df428(0x16);
  FUN_004deda4();
  return;
}



/* @004dedc8 file=? name=FUN_004dedc8 */

void FUN_004dedc8(void)

{
  return;
}



/* @004dedcc file=? name=FUN_004dedcc */

void __cdecl FUN_004dedcc(int param_1,int param_2,UINT param_3)

{
  if (param_1 == 0) {
    while (DAT_00520c10 != 0) {
      DAT_00520c10 = DAT_00520c10 + -1;
      (**(code **)(&DAT_00525228 + DAT_00520c10 * 4))();
    }
    FUN_004df6bc();
    (*(code *)PTR_FUN_00520c14)();
  }
  if (param_2 == 0) {
    if (param_1 == 0) {
      (*(code *)PTR_FUN_00520c18)();
      (*(code *)PTR_FUN_00520c1c)();
    }
    FUN_004df734(param_3);
  }
  return;
}



/* @004dee24 file=? name=FUN_004dee24 */

void __cdecl FUN_004dee24(UINT param_1)

{
  FUN_004dedcc(0,0,param_1);
  return;
}



/* @004dee3c file=? name=FUN_004dee3c */

void __cdecl FUN_004dee3c(UINT param_1)

{
  FUN_004dedcc(1,0,param_1);
  return;
}



/* @004dee74 file=? name=FUN_004dee74 */

int __cdecl FUN_004dee74(char *param_1)

{
  int iVar1;
  int iVar2;
  int *piVar3;
  
  iVar1 = FUN_004d4a78(param_1);
  for (piVar3 = DAT_005252b4; *piVar3 != 0; piVar3 = piVar3 + 1) {
    iVar2 = FUN_004d4ae0((char *)*piVar3,param_1,iVar1);
    if ((iVar2 == 0) && (*(char *)(*piVar3 + iVar1) == '=')) break;
  }
  if (*piVar3 == 0) {
    iVar1 = 0;
  }
  else {
    iVar1 = iVar1 + *piVar3 + 1;
  }
  return iVar1;
}



/* @004deec4 file=? name=FUN_004deec4 */

void FUN_004deec4(void)

{
  return;
}



/* @004df048 file=? name=FUN_004df048 */

void __cdecl FUN_004df048(int *param_1,int *param_2)

{
  if ((*(char *)*param_2 == '\\') && (((char *)*param_2)[1] == '\"')) {
    *(undefined1 *)*param_1 = 0x22;
    *param_2 = *param_2 + 2;
  }
  else {
    *(undefined1 *)*param_1 = *(undefined1 *)*param_2;
    *param_2 = *param_2 + 1;
  }
  *param_1 = *param_1 + 1;
  return;
}



/* @004df078 file=? name=FUN_004df078 */

void __cdecl FUN_004df078(int *param_1,int param_2)

{
  int iVar1;
  int *piVar2;
  uint uVar3;
  uint uVar4;
  int *piVar5;
  int *piVar6;
  
  if (DAT_005252a8 == DAT_005252b0) {
    DAT_005252b0 = DAT_005252b0 + 0x10;
    DAT_005252ac = FUN_004de760(DAT_005252ac,DAT_005252b0 * 4);
    if (DAT_005252ac == (int *)0x0) {
      FUN_004ded48(s_No_space_for_command_line_argume_00520c4a);
    }
  }
  piVar2 = param_1;
  if (param_2 != 0) {
    iVar1 = FUN_004d4a78((char *)param_1);
    piVar2 = FUN_004de55c(iVar1 + 1);
    if (piVar2 == (int *)0x0) {
      FUN_004ded48(s_No_space_for_command_line_argume_00520c74);
    }
    uVar3 = 0xffffffff;
    do {
      piVar5 = param_1;
      if (uVar3 == 0) break;
      uVar3 = uVar3 - 1;
      piVar5 = (int *)((int)param_1 + 1);
      iVar1 = *param_1;
      param_1 = piVar5;
    } while ((char)iVar1 != '\0');
    uVar3 = ~uVar3;
    piVar5 = (int *)((int)piVar5 - uVar3);
    piVar6 = piVar2;
    for (uVar4 = uVar3 >> 2; uVar4 != 0; uVar4 = uVar4 - 1) {
      *piVar6 = *piVar5;
      piVar5 = piVar5 + 1;
      piVar6 = piVar6 + 1;
    }
    for (uVar3 = uVar3 & 3; uVar3 != 0; uVar3 = uVar3 - 1) {
      *(char *)piVar6 = (char)*piVar5;
      piVar5 = (int *)((int)piVar5 + 1);
      piVar6 = (int *)((int)piVar6 + 1);
    }
  }
  DAT_005252ac[DAT_005252a8] = (int)piVar2;
  DAT_005252a8 = DAT_005252a8 + 1;
  return;
}



/* @004df128 file=? name=FUN_004df128 */

void __cdecl FUN_004df128(int *param_1)

{
  FUN_004df078(param_1,0);
  return;
}



/* @004df13c file=? name=FUN_004df13c */

char * __cdecl FUN_004df13c(char *param_1,char *param_2)

{
  uint uVar1;
  uint uVar2;
  char cVar3;
  char *pcVar4;
  char *pcVar5;
  
  for (; (cVar3 = *param_2, cVar3 != '\0' && (cVar3 != '=')); param_2 = param_2 + 1) {
    if (('`' < cVar3) && (cVar3 < '{')) {
      cVar3 = cVar3 + -0x20;
    }
    *param_1 = cVar3;
    param_1 = param_1 + 1;
  }
  uVar1 = 0xffffffff;
  do {
    pcVar4 = param_2;
    if (uVar1 == 0) break;
    uVar1 = uVar1 - 1;
    pcVar4 = param_2 + 1;
    cVar3 = *param_2;
    param_2 = pcVar4;
  } while (cVar3 != '\0');
  uVar1 = ~uVar1;
  pcVar4 = pcVar4 + -uVar1;
  pcVar5 = param_1;
  for (uVar2 = uVar1 >> 2; uVar2 != 0; uVar2 = uVar2 - 1) {
    *(undefined4 *)pcVar5 = *(undefined4 *)pcVar4;
    pcVar4 = pcVar4 + 4;
    pcVar5 = pcVar5 + 4;
  }
  for (uVar1 = uVar1 & 3; uVar1 != 0; uVar1 = uVar1 - 1) {
    *pcVar5 = *pcVar4;
    pcVar4 = pcVar4 + 1;
    pcVar5 = pcVar5 + 1;
  }
  return param_1;
}



/* @004df190 file=? name=FUN_004df190 */

void FUN_004df190(void)

{
  int iVar1;
  int *piVar2;
  char *pcVar3;
  int iVar4;
  
  iVar4 = 0;
  pcVar3 = DAT_005252c8;
  while( true ) {
    iVar1 = FUN_004d4a78(pcVar3);
    if (iVar1 == 0) break;
    iVar4 = iVar4 + 1;
    pcVar3 = pcVar3 + iVar1 + 1;
  }
  DAT_005252b4 = FUN_004de55c((iVar4 + 1) * 4);
  if (DAT_005252b4 != (int *)0x0) {
    iVar4 = 0;
    pcVar3 = DAT_005252c8;
    while( true ) {
      iVar1 = FUN_004d4a78(pcVar3);
      if (iVar1 == 0) break;
      piVar2 = FUN_004de55c(iVar1 + 1);
      if (piVar2 == (int *)0x0) break;
      FUN_004df13c((char *)piVar2,pcVar3);
      DAT_005252b4[iVar4] = (int)piVar2;
      iVar4 = iVar4 + 1;
      pcVar3 = pcVar3 + iVar1 + 1;
    }
    DAT_005252d8 = DAT_005252b4;
    DAT_005252b4[iVar4] = 0;
  }
  return;
}



/* @004df214 file=? name=FUN_004df214 */

int __cdecl FUN_004df214(int param_1)

{
  int iVar1;
  int *piVar2;
  
  iVar1 = 0;
  piVar2 = &DAT_00520cc8;
  do {
    if (param_1 == *piVar2) {
      return iVar1;
    }
    iVar1 = iVar1 + 1;
    piVar2 = piVar2 + 1;
  } while (iVar1 < 10);
  return -1;
}



/* @004df234 file=? name=FUN_004df234 */

undefined4 __cdecl FUN_004df234(int *param_1,undefined4 param_2,int param_3)

{
  code *pcVar1;
  undefined4 uVar2;
  int iVar3;
  uint uVar4;
  undefined4 local_8;
  
  uVar4 = 0;
  iVar3 = *param_1;
  if (iVar3 < -0x3fffff6e) {
    if (iVar3 == -0x3fffff6f) {
      iVar3 = 2;
      local_8 = 0x84;
      uVar4 = 8;
    }
    else if (iVar3 == -0x3ffffffb) {
      iVar3 = 3;
      local_8 = 0xc;
    }
    else if (iVar3 == -0x3fffffe3) {
      iVar3 = 1;
      local_8 = 0x14;
    }
    else if (iVar3 == -0x3fffff72) {
      iVar3 = 2;
      local_8 = 0x83;
      uVar4 = 4;
    }
    else {
      if (iVar3 != -0x3fffff70) {
        return 1;
      }
      iVar3 = 2;
      local_8 = 0x81;
      uVar4 = 1;
    }
  }
  else if (iVar3 == -0x3fffff6e) {
    iVar3 = 2;
    local_8 = 0x87;
    uVar4 = 0x49;
  }
  else if (iVar3 == -0x3fffff6d) {
    iVar3 = 2;
    local_8 = 0x85;
    uVar4 = 0x10;
  }
  else if (iVar3 == -0x3fffff6c) {
    iVar3 = 2;
    local_8 = 0x7f;
  }
  else {
    if (iVar3 != -0x3fffff6a) {
      return 1;
    }
    iVar3 = 1;
    local_8 = 0x16;
  }
  pcVar1 = *(code **)(&DAT_00520ca0 + iVar3 * 4);
  if (pcVar1 == (code *)0x1) {
    uVar2 = 0;
  }
  else if (pcVar1 == (code *)0x0) {
    uVar2 = 1;
  }
  else {
    *(undefined4 *)(&DAT_00520ca0 + iVar3 * 4) = 0;
    if (((iVar3 == 1) || (iVar3 == 3)) || (iVar3 == 2)) {
      FUN_004dc9a0();
      FUN_004dc9f8();
      (*pcVar1)((&DAT_00520cc8)[iVar3],local_8);
      *(uint *)(param_3 + 0x20) = *(uint *)(param_3 + 0x20) & ~uVar4;
    }
    else {
      (*pcVar1)((&DAT_00520cc8)[iVar3]);
    }
    uVar2 = 0;
  }
  return uVar2;
}



/* @004df3a4 file=? name=FUN_004df3a4 */

undefined4 FUN_004df3a4(int param_1)

{
  int iVar1;
  
  iVar1 = 2;
  if (param_1 != 0) {
    iVar1 = 0x15;
  }
  FUN_004df428(iVar1);
  return 1;
}



/* @004df3c8 file=? name=FUN_004df3c8 */

undefined4 __cdecl FUN_004df3c8(int param_1,undefined4 param_2)

{
  undefined4 uVar1;
  int iVar2;
  
  if (DAT_00520c9c == '\0') {
    DAT_00524c6c = FUN_004df234;
    SetConsoleCtrlHandler(FUN_004df3a4,1);
    DAT_00520c9c = '\x01';
  }
  iVar2 = FUN_004df214(param_1);
  if (iVar2 == -1) {
    DAT_00520bcc = 0x13;
    return 0xffffffff;
  }
  uVar1 = *(undefined4 *)(&DAT_00520ca0 + iVar2 * 4);
  *(undefined4 *)(&DAT_00520ca0 + iVar2 * 4) = param_2;
  return uVar1;
}



/* @004df428 file=? name=FUN_004df428 */

undefined4 __cdecl FUN_004df428(int param_1)

{
  code *pcVar1;
  int iVar2;
  undefined4 uVar3;
  
  iVar2 = FUN_004df214(param_1);
  if (iVar2 == -1) {
    uVar3 = 1;
  }
  else {
    pcVar1 = *(code **)(&DAT_00520ca0 + iVar2 * 4);
    if (pcVar1 != (code *)0x1) {
      if (pcVar1 == (code *)0x0) {
        if ((1 < param_1 - 0x10U) && (param_1 != 0x14)) {
          if (param_1 == 0x16) {
            FUN_004deda4();
          }
          else {
            FUN_004dee3c(3);
          }
        }
      }
      else {
        *(undefined4 *)(&DAT_00520ca0 + iVar2 * 4) = 0;
        if ((&DAT_00520cf0)[iVar2] == '\0') {
          (*pcVar1)(param_1);
        }
        else {
          (*pcVar1)(param_1,(&DAT_00520cf0)[iVar2]);
        }
      }
    }
    uVar3 = 0;
  }
  return uVar3;
}



/* @004df4a4 file=? name=FUN_004df4a4 */

undefined4 FUN_004df4a4(void)

{
  return 0;
}



/* @004df4a8 file=? name=FUN_004df4a8 */

undefined4 FUN_004df4a8(void)

{
  return 0;
}



/* @004df4ac file=? name=FUN_004df4ac */

undefined4 __cdecl FUN_004df4ac(int *param_1,uint param_2)

{
  undefined4 *puVar1;
  char *pcVar2;
  undefined4 uVar3;
  uint uVar4;
  char *pcVar5;
  int *local_10;
  int local_c;
  char *local_8;
  
  uVar4 = 0;
  if (param_2 == 0) {
    uVar4 = 0xffff;
  }
  local_8 = (char *)0x0;
  local_10 = param_1;
  for (local_c = 0; local_10 = local_10 + 1, local_c < *param_1; local_c = local_c + 1) {
    puVar1 = (undefined4 *)*local_10;
    if (param_2 == 0) {
      pcVar2 = (char *)*puVar1;
      pcVar5 = (char *)puVar1[1];
    }
    else {
      pcVar2 = (char *)puVar1[2];
      pcVar5 = (char *)puVar1[3];
    }
    for (; (pcVar2 < pcVar5 && (*(int *)(pcVar2 + 2) != 0)); pcVar2 = pcVar2 + 6) {
      if ((*pcVar2 == '\0') && (param_2 == uVar4 <= (byte)pcVar2[1])) {
        uVar4 = (uint)(byte)pcVar2[1];
        local_8 = pcVar2;
      }
    }
  }
  if (local_8 == (char *)0x0) {
    uVar3 = 0;
  }
  else {
    *local_8 = '\x01';
    uVar3 = *(undefined4 *)(local_8 + 2);
  }
  return uVar3;
}



/* @004df558 file=? name=FUN_004df558 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void __cdecl FUN_004df558(int param_1)

{
  char cVar1;
  int *piVar2;
  code *pcVar3;
  HMODULE pHVar4;
  UINT UVar5;
  char cVar6;
  int *piVar7;
  char *pcVar8;
  undefined4 uVar9;
  undefined4 uVar10;
  int local_10;
  undefined1 local_c [8];
  
  _DAT_005252e8 = *(uint *)(param_1 + 0x10) & 1;
  FUN_004dcd7c();
  FUN_004dd494(*(undefined **)(param_1 + 0x1c),*(undefined **)(param_1 + 0x20));
  FUN_004d6db0(*(undefined **)(param_1 + 0x28));
  _DAT_005252dc = 1;
  _DAT_005252e0 = param_1;
  DAT_005252c4 = local_c;
  FUN_004d69d0();
  DAT_005252c8 = GetEnvironmentStrings();
  DAT_005252cc = GetCommandLineA();
  FUN_004deec4();
  piVar2 = (int *)FUN_004df4a4();
  if (piVar2 != (int *)0x0) {
    piVar2[*piVar2 + 1] = -1;
    while (pcVar3 = (code *)FUN_004df4ac(piVar2,0), pcVar3 != (code *)0x0) {
      (*pcVar3)();
    }
    piVar7 = piVar2;
    for (local_10 = 0; piVar7 = piVar7 + 1, local_10 < *piVar2; local_10 = local_10 + 1) {
      (**(code **)(*piVar7 + 0x18))(0,*(undefined4 *)(*piVar7 + 0x14));
    }
  }
  while (pcVar3 = (code *)FUN_004df4ac((int *)&DAT_005252dc,0), pcVar3 != (code *)0x0) {
    (*pcVar3)();
  }
  pcVar8 = DAT_005252cc;
  if ((*(byte *)(param_1 + 0x10) & 1) == 0) {
    UVar5 = (**(code **)(param_1 + 0x18))(DAT_005252d0,DAT_005252d4,DAT_005252d8);
    FUN_004dee24(UVar5);
  }
  else {
    for (; (*pcVar8 == ' ' || (*pcVar8 == '\t')); pcVar8 = pcVar8 + 1) {
    }
    if (*pcVar8 == '\"') {
      cVar6 = '\"';
      pcVar8 = pcVar8 + 1;
    }
    else {
      cVar6 = ' ';
    }
    for (; ((cVar1 = *pcVar8, cVar1 != '\0' && (cVar6 != cVar1)) && (cVar1 != '\t'));
        pcVar8 = pcVar8 + 1) {
    }
    if (*pcVar8 == '\"') {
      pcVar8 = pcVar8 + 1;
    }
    for (; ((cVar6 = *pcVar8, cVar6 != '\0' && (cVar6 == ' ')) || (cVar6 == '\t'));
        pcVar8 = pcVar8 + 1) {
    }
    uVar10 = 10;
    uVar9 = 0;
    pHVar4 = GetModuleHandleA((LPCSTR)0x0);
    UVar5 = (**(code **)(param_1 + 0x18))(pHVar4,uVar9,pcVar8,uVar10);
    FUN_004dee24(UVar5);
  }
  return;
}



/* @004df6bc file=? name=FUN_004df6bc */

void FUN_004df6bc(void)

{
  code *pcVar1;
  int *piVar2;
  int *piVar3;
  int iVar4;
  
  while (pcVar1 = (code *)FUN_004df4ac((int *)&DAT_005252dc,1), pcVar1 != (code *)0x0) {
    (*pcVar1)();
  }
  while (pcVar1 = (code *)FUN_004df4ac((int *)&DAT_005252bc,1), pcVar1 != (code *)0x0) {
    (*pcVar1)();
  }
  piVar2 = (int *)FUN_004df4a8();
  if (piVar2 != (int *)0x0) {
    while (pcVar1 = (code *)FUN_004df4ac(piVar2,1), pcVar1 != (code *)0x0) {
      (*pcVar1)();
    }
    piVar3 = piVar2;
    for (iVar4 = 0; piVar3 = piVar3 + 1, iVar4 < *piVar2; iVar4 = iVar4 + 1) {
      (**(code **)(*piVar3 + 0x18))(1,*(undefined4 *)(*piVar3 + 0x14));
    }
  }
  return;
}



/* @004df734 file=? name=FUN_004df734 */

void FUN_004df734(UINT param_1)

{
                    /* WARNING: Subroutine does not return */
  ExitProcess(param_1);
}



/* @004df748 file=? name=FUN_004df748 */

void __cdecl FUN_004df748(undefined1 *param_1)

{
  FUN_004d7f10(param_1,s__s__s__02d__02d__02d__02d__4d_s_00520d00);
  return;
}



/* @004df794 file=? name=FUN_004df794 */

undefined * FUN_004df794(void)

{
  FUN_004df748(&DAT_005252ec);
  return &DAT_005252ec;
}



/* @004df7b4 file=? name=FUN_004df7b4 */

void __cdecl FUN_004df7b4(int *param_1)

{
  FUN_004df950(param_1);
  FUN_004df794();
  return;
}



/* @004df7cc file=? name=FUN_004df7cc */

undefined4 * __cdecl FUN_004df7cc(uint param_1,int param_2)

{
  ulonglong uVar1;
  bool bVar2;
  undefined3 extraout_var;
  uint uVar3;
  uint uVar4;
  int local_8;
  
  DAT_00525308 = param_1 % 0x3c;
  DAT_0052530c = (undefined4)(((ulonglong)param_1 / 0x3c) % 0x3c);
  uVar1 = ((ulonglong)param_1 / 0x3c) / 0x3c;
  local_8 = (int)(uVar1 / 0x88f8);
  DAT_0052531c = local_8 * 4 + 0x46;
  local_8 = local_8 * 0x5b5;
  uVar4 = (uint)(uVar1 % 0x88f8);
  while( true ) {
    uVar3 = 0x2238;
    if ((DAT_0052531c & 3) == 0) {
      uVar3 = 0x2250;
    }
    if (uVar4 < uVar3) break;
    local_8 = local_8 + uVar3 / 0x18;
    DAT_0052531c = DAT_0052531c + 1;
    uVar4 = uVar4 - uVar3;
  }
  if (((param_2 == 0) || (DAT_00520ef4 == 0)) ||
     (bVar2 = FUN_004dfb04(uVar4 % 0x18,uVar4 / 0x18,0,DAT_0052531c - 0x46),
     CONCAT31(extraout_var,bVar2) == 0)) {
    DAT_00525328 = 0;
  }
  else {
    uVar4 = uVar4 + 1;
    DAT_00525328 = 1;
  }
  DAT_00525310 = uVar4 % 0x18;
  DAT_00525324 = uVar4 / 0x18;
  DAT_00525320 = (local_8 + DAT_00525324 + 4) % 7;
  uVar4 = DAT_00525324 + 1;
  DAT_00525314 = uVar4;
  if ((((DAT_0052531c & 3) == 0) && (DAT_00525314 = DAT_00525324, uVar4 < 0x3d)) &&
     (DAT_00525314 = uVar4, uVar4 == 0x3c)) {
    DAT_00525318 = 1;
    DAT_00525314 = 0x1d;
  }
  else {
    for (DAT_00525318 = 0; (uint)(int)(char)(&DAT_00520dc4)[DAT_00525318] < DAT_00525314;
        DAT_00525318 = DAT_00525318 + 1) {
      DAT_00525314 = DAT_00525314 - (int)(char)(&DAT_00520dc4)[DAT_00525318];
    }
  }
  return &DAT_00525308;
}



/* @004df938 file=? name=FUN_004df938 */

void __cdecl FUN_004df938(uint *param_1)

{
  FUN_004df7cc(*param_1,0);
  return;
}



/* @004df950 file=? name=FUN_004df950 */

undefined4 * __cdecl FUN_004df950(int *param_1)

{
  undefined4 *puVar1;
  
  if (*param_1 < DAT_00520ef0) {
    return (undefined4 *)0x0;
  }
  puVar1 = FUN_004df7cc(*param_1 - DAT_00520ef0,1);
  return puVar1;
}



/* @004dfb04 file=? name=FUN_004dfb04 */

bool __cdecl FUN_004dfb04(uint param_1,uint param_2,uint param_3,uint param_4)

{
  uint *puVar1;
  int iVar2;
  uint uVar3;
  bool bVar4;
  uint local_8;
  
  if (param_3 == 0) {
    local_8 = param_2;
    if ((0x3a < param_2) && ((param_4 + 0x46 & 3) == 0)) {
      local_8 = param_2 - 1;
    }
    param_3 = 0;
    for (puVar1 = &DAT_00520dd0; *puVar1 <= local_8; puVar1 = puVar1 + 1) {
      param_3 = param_3 + 1;
    }
  }
  else {
    param_2 = param_2 + (&DAT_00520dcc)[param_3];
    if ((2 < param_3) && ((param_4 + 0x46 & 3) == 0)) {
      param_2 = param_2 + 1;
    }
  }
  if ((param_3 < 4) || (10 < param_3)) {
    bVar4 = false;
  }
  else if ((param_3 < 5) || (9 < param_3)) {
    if ((param_4 < 0x11) || (param_3 != 4)) {
      iVar2 = (&DAT_00520dd0)[param_3];
    }
    else {
      iVar2 = iRam00520ddc + 7;
    }
    if ((param_4 + 0x46 & 3) != 0) {
      iVar2 = iVar2 + -1;
    }
    uVar3 = iVar2 - ((param_4 + 1 >> 2) + iVar2 + param_4 * 0x16d + 4) % 7;
    if (param_3 == 4) {
      if (uVar3 < param_2) {
        bVar4 = true;
      }
      else if (param_2 < uVar3) {
        bVar4 = false;
      }
      else {
        bVar4 = 1 < param_1;
      }
    }
    else if (param_2 < uVar3) {
      bVar4 = true;
    }
    else if (uVar3 < param_2) {
      bVar4 = false;
    }
    else {
      bVar4 = param_1 < 2;
    }
  }
  else {
    bVar4 = true;
  }
  return bVar4;
}



/* @004dfc18 file=? name=FUN_004dfc18 */

int __cdecl FUN_004dfc18(int param_1,int param_2,int param_3,int param_4,int param_5,int param_6)

{
  int iVar1;
  char *pcVar2;
  bool bVar3;
  char *pcVar4;
  int iVar5;
  undefined3 extraout_var;
  uint uVar6;
  int iVar7;
  uint uVar8;
  uint uVar9;
  int local_8;
  
  if ((param_1 < 0x46) || (0x8a < param_1)) {
    local_8 = -1;
  }
  else {
    iVar1 = param_5 + param_6 / 0x3c;
    iVar5 = param_4 + iVar1 / 0x3c;
    uVar8 = param_3 + iVar5 / 0x18;
    uVar6 = iVar5 % 0x18;
    uVar9 = param_1 + param_2 / 0xc;
    pcVar2 = &DAT_00520dc4 + param_2 % 0xc;
    iVar5 = param_2 % 0xc;
    while (iVar7 = iVar5, pcVar4 = pcVar2, (int)*pcVar4 <= (int)uVar8) {
      if (((uVar9 & 3) == 0) && (iVar7 == 1)) {
        if ((int)uVar8 < 0x1d) break;
        iVar5 = -0x1d;
      }
      else {
        iVar5 = -(int)*pcVar4;
      }
      uVar8 = uVar8 + iVar5;
      pcVar2 = pcVar4 + 1;
      iVar5 = iVar7 + 1;
      if (0xb < iVar7 + 1) {
        uVar9 = uVar9 + 1;
        pcVar2 = pcVar4 + -0xb;
        iVar5 = iVar7 + -0xb;
      }
    }
    iVar5 = uVar9 - 0x44;
    if (iVar5 < 0) {
      iVar5 = uVar9 - 0x41;
    }
    iVar5 = iVar5 >> 2;
    if (((uVar9 & 3) == 0) && (iVar7 < 2)) {
      iVar5 = iVar5 + -1;
    }
    local_8 = (iVar5 + (uVar9 - 0x46) * 0x16d + (&DAT_00520dd0)[iVar7] + uVar8) * 0x15180 +
              uVar6 * 0xe10 + (iVar1 % 0x3c) * 0x3c + param_6 % 0x3c + DAT_00520ef0;
    if ((DAT_00520ef4 != 0) &&
       (bVar3 = FUN_004dfb04(uVar6,uVar8,iVar7 + 1,uVar9 - 0x46), CONCAT31(extraout_var,bVar3) != 0)
       ) {
      local_8 = local_8 + -0xe10;
    }
    if (local_8 < 1) {
      local_8 = -1;
    }
  }
  return local_8;
}



/* @004dfd90 file=? name=FUN_004dfd90 */

/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

int FUN_004dfd90(void)

{
  DWORD DVar1;
  
  DVar1 = GetTickCount();
  return DVar1 - _DAT_00520f00;
}



/* @004dfda8 file=? name=FUN_004dfda8 */

void __cdecl FUN_004dfda8(int *param_1)

{
  int iVar1;
  _SYSTEMTIME local_14;
  
  GetLocalTime(&local_14);
  iVar1 = FUN_004dfc18(local_14.wYear - 0x76c,local_14.wMonth - 1,local_14.wDay - 1,
                       (uint)local_14.wHour,(uint)local_14.wMinute,(uint)local_14.wSecond);
  if (param_1 != (int *)0x0) {
    *param_1 = iVar1;
  }
  return;
}



/* @004dfdf3 file=? name=GetStartupInfoA */

void GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo)

{
                    /* WARNING: Could not recover jumptable at 0x004dfdf3. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  GetStartupInfoA(lpStartupInfo);
  return;
}



/* @004dfdf9 file=? name=DeleteFileA */

BOOL DeleteFileA(LPCSTR lpFileName)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfdf9. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = DeleteFileA(lpFileName);
  return BVar1;
}



/* @004dfdff file=? name=ExitProcess */

void ExitProcess(UINT uExitCode)

{
                    /* WARNING: Could not recover jumptable at 0x004dfdff. Too many branches */
                    /* WARNING: Subroutine does not return */
                    /* WARNING: Treating indirect jump as call */
  ExitProcess(uExitCode);
  return;
}



/* @004dfe05 file=? name=CloseHandle */

BOOL CloseHandle(HANDLE hObject)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe05. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = CloseHandle(hObject);
  return BVar1;
}



/* @004dfe0b file=? name=GetConsoleMode */

BOOL GetConsoleMode(HANDLE hConsoleHandle,LPDWORD lpMode)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe0b. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = GetConsoleMode(hConsoleHandle,lpMode);
  return BVar1;
}



/* @004dfe11 file=? name=GetCurrentDirectoryA */

DWORD GetCurrentDirectoryA(DWORD nBufferLength,LPSTR lpBuffer)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe11. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetCurrentDirectoryA(nBufferLength,lpBuffer);
  return DVar1;
}



/* @004dfe17 file=? name=GetCurrentThreadId */

DWORD GetCurrentThreadId(void)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe17. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetCurrentThreadId();
  return DVar1;
}



/* @004dfe1d file=? name=GetDriveTypeA */

UINT GetDriveTypeA(LPCSTR lpRootPathName)

{
  UINT UVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe1d. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  UVar1 = GetDriveTypeA(lpRootPathName);
  return UVar1;
}



/* @004dfe23 file=? name=CreateFileA */

HANDLE CreateFileA(LPCSTR lpFileName,DWORD dwDesiredAccess,DWORD dwShareMode,
                  LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD dwCreationDisposition,
                  DWORD dwFlagsAndAttributes,HANDLE hTemplateFile)

{
  HANDLE pvVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe23. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  pvVar1 = CreateFileA(lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,
                       dwCreationDisposition,dwFlagsAndAttributes,hTemplateFile);
  return pvVar1;
}



/* @004dfe29 file=? name=GetEnvironmentVariableA */

DWORD GetEnvironmentVariableA(LPCSTR lpName,LPSTR lpBuffer,DWORD nSize)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe29. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetEnvironmentVariableA(lpName,lpBuffer,nSize);
  return DVar1;
}



/* @004dfe2f file=? name=GetFileAttributesA */

DWORD GetFileAttributesA(LPCSTR lpFileName)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe2f. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetFileAttributesA(lpFileName);
  return DVar1;
}



/* @004dfe35 file=? name=GetFileType */

DWORD GetFileType(HANDLE hFile)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe35. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetFileType(hFile);
  return DVar1;
}



/* @004dfe3b file=? name=GetLastError */

DWORD GetLastError(void)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe3b. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetLastError();
  return DVar1;
}



/* @004dfe41 file=? name=GetLocalTime */

void GetLocalTime(LPSYSTEMTIME lpSystemTime)

{
                    /* WARNING: Could not recover jumptable at 0x004dfe41. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  GetLocalTime(lpSystemTime);
  return;
}



/* @004dfe47 file=? name=GetLogicalDrives */

DWORD GetLogicalDrives(void)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe47. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetLogicalDrives();
  return DVar1;
}



/* @004dfe4d file=? name=GetModuleFileNameA */

DWORD GetModuleFileNameA(HMODULE hModule,LPSTR lpFilename,DWORD nSize)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe4d. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetModuleFileNameA(hModule,lpFilename,nSize);
  return DVar1;
}



/* @004dfe53 file=? name=GetModuleHandleA */

HMODULE GetModuleHandleA(LPCSTR lpModuleName)

{
  HMODULE pHVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe53. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  pHVar1 = GetModuleHandleA(lpModuleName);
  return pHVar1;
}



/* @004dfe59 file=? name=GetNumberOfConsoleInputEvents */

BOOL GetNumberOfConsoleInputEvents(HANDLE hConsoleInput,LPDWORD lpNumberOfEvents)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe59. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = GetNumberOfConsoleInputEvents(hConsoleInput,lpNumberOfEvents);
  return BVar1;
}



/* @004dfe5f file=? name=GetEnvironmentStrings */

LPCH GetEnvironmentStrings(void)

{
  LPCH pCVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe5f. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  pCVar1 = GetEnvironmentStrings();
  return pCVar1;
}



/* @004dfe65 file=? name=GetCommandLineA */

LPSTR GetCommandLineA(void)

{
  LPSTR pCVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe65. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  pCVar1 = GetCommandLineA();
  return pCVar1;
}



/* @004dfe6b file=? name=GetStdHandle */

HANDLE GetStdHandle(DWORD nStdHandle)

{
  HANDLE pvVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe6b. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  pvVar1 = GetStdHandle(nStdHandle);
  return pvVar1;
}



/* @004dfe71 file=? name=GetTickCount */

DWORD GetTickCount(void)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe71. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetTickCount();
  return DVar1;
}



/* @004dfe7d file=? name=GetVersion */

DWORD GetVersion(void)

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe7d. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = GetVersion();
  return DVar1;
}



/* @004dfe83 file=? name=PeekConsoleInputA */

BOOL PeekConsoleInputA(HANDLE hConsoleInput,PINPUT_RECORD lpBuffer,DWORD nLength,
                      LPDWORD lpNumberOfEventsRead)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe83. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = PeekConsoleInputA(hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead);
  return BVar1;
}



/* @004dfe89 file=? name=RaiseException */

void RaiseException(DWORD dwExceptionCode,DWORD dwExceptionFlags,DWORD nNumberOfArguments,
                   ULONG_PTR *lpArguments)

{
                    /* WARNING: Could not recover jumptable at 0x004dfe89. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  RaiseException(dwExceptionCode,dwExceptionFlags,nNumberOfArguments,lpArguments);
  return;
}



/* @004dfe8f file=? name=ReadConsoleInputA */

BOOL ReadConsoleInputA(HANDLE hConsoleInput,PINPUT_RECORD lpBuffer,DWORD nLength,
                      LPDWORD lpNumberOfEventsRead)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe8f. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = ReadConsoleInputA(hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead);
  return BVar1;
}



/* @004dfe95 file=? name=ReadFile */

BOOL ReadFile(HANDLE hFile,LPVOID lpBuffer,DWORD nNumberOfBytesToRead,LPDWORD lpNumberOfBytesRead,
             LPOVERLAPPED lpOverlapped)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfe95. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = ReadFile(hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,lpOverlapped);
  return BVar1;
}



/* @004dfe9b file=? name=RtlUnwind */

void RtlUnwind(PVOID TargetFrame,PVOID TargetIp,PEXCEPTION_RECORD ExceptionRecord,PVOID ReturnValue)

{
                    /* WARNING: Could not recover jumptable at 0x004dfe9b. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  RtlUnwind(TargetFrame,TargetIp,ExceptionRecord,ReturnValue);
  return;
}



/* @004dfea1 file=? name=SetConsoleCtrlHandler */

BOOL SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine,BOOL Add)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfea1. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = SetConsoleCtrlHandler(HandlerRoutine,Add);
  return BVar1;
}



/* @004dfea7 file=? name=SetConsoleMode */

BOOL SetConsoleMode(HANDLE hConsoleHandle,DWORD dwMode)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfea7. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = SetConsoleMode(hConsoleHandle,dwMode);
  return BVar1;
}



/* @004dfead file=? name=SetCurrentDirectoryA */

BOOL SetCurrentDirectoryA(LPCSTR lpPathName)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfead. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = SetCurrentDirectoryA(lpPathName);
  return BVar1;
}



/* @004dfeb3 file=? name=SetEnvironmentVariableA */

BOOL SetEnvironmentVariableA(LPCSTR lpName,LPCSTR lpValue)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfeb3. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = SetEnvironmentVariableA(lpName,lpValue);
  return BVar1;
}



/* @004dfeb9 file=? name=SetFilePointer */

DWORD SetFilePointer(HANDLE hFile,LONG lDistanceToMove,PLONG lpDistanceToMoveHigh,DWORD dwMoveMethod
                    )

{
  DWORD DVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfeb9. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  DVar1 = SetFilePointer(hFile,lDistanceToMove,lpDistanceToMoveHigh,dwMoveMethod);
  return DVar1;
}



/* @004dfebf file=? name=SetHandleCount */

UINT SetHandleCount(UINT uNumber)

{
  UINT UVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfebf. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  UVar1 = SetHandleCount(uNumber);
  return UVar1;
}



/* @004dfec5 file=? name=UnhandledExceptionFilter */

LONG UnhandledExceptionFilter(_EXCEPTION_POINTERS *ExceptionInfo)

{
  LONG LVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfec5. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  LVar1 = UnhandledExceptionFilter(ExceptionInfo);
  return LVar1;
}



/* @004dfecb file=? name=VirtualAlloc */

LPVOID VirtualAlloc(LPVOID lpAddress,SIZE_T dwSize,DWORD flAllocationType,DWORD flProtect)

{
  LPVOID pvVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfecb. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  pvVar1 = VirtualAlloc(lpAddress,dwSize,flAllocationType,flProtect);
  return pvVar1;
}



/* @004dfed1 file=? name=VirtualFree */

BOOL VirtualFree(LPVOID lpAddress,SIZE_T dwSize,DWORD dwFreeType)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfed1. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = VirtualFree(lpAddress,dwSize,dwFreeType);
  return BVar1;
}



/* @004dfed7 file=? name=WriteFile */

BOOL WriteFile(HANDLE hFile,LPCVOID lpBuffer,DWORD nNumberOfBytesToWrite,
              LPDWORD lpNumberOfBytesWritten,LPOVERLAPPED lpOverlapped)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfed7. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = WriteFile(hFile,lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,lpOverlapped);
  return BVar1;
}



/* @004dfedd file=? name=GetProcAddress */

FARPROC GetProcAddress(HMODULE hModule,LPCSTR lpProcName)

{
  FARPROC pFVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfedd. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  pFVar1 = GetProcAddress(hModule,lpProcName);
  return pFVar1;
}



/* @004dfee3 file=? name=MessageBoxA */

int MessageBoxA(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType)

{
  int iVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfee3. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  iVar1 = MessageBoxA(hWnd,lpText,lpCaption,uType);
  return iVar1;
}



/* @004dfee9 file=? name=EnumThreadWindows */

BOOL EnumThreadWindows(DWORD dwThreadId,WNDENUMPROC lpfn,LPARAM lParam)

{
  BOOL BVar1;
  
                    /* WARNING: Could not recover jumptable at 0x004dfee9. Too many branches */
                    /* WARNING: Treating indirect jump as call */
  BVar1 = EnumThreadWindows(dwThreadId,lpfn,lParam);
  return BVar1;
}



