// Decompiled from acclient.exe — chunk 0x00400000
// Ghidra 12.0.4 + pyghidra headless

// --- FUN_00401000 at 0x00401000 (size: 48) ---


void FUN_00401000(undefined4 param_1,undefined4 param_2,int param_3,code *param_4)



{

  if (-1 < param_3 + -1) {

    do {

      (*param_4)();

      param_3 = param_3 + -1;

    } while (param_3 != 0);

  }

  return;

}





// --- FUN_00401030 at 0x00401030 (size: 49) ---


void FUN_00401030(undefined4 param_1,undefined4 param_2,int param_3,code *param_4)



{

  if (-1 < param_3 + -1) {

    do {

      (*param_4)();

      param_3 = param_3 + -1;

    } while (param_3 != 0);

  }

  return;

}





// --- FUN_00401070 at 0x00401070 (size: 28) ---


void FUN_00401070(int param_1,char *param_2)



{

  char cVar1;

  

  param_1 = param_1 - (int)param_2;

  do {

    cVar1 = *param_2;

    param_2[param_1] = cVar1;

    param_2 = param_2 + 1;

  } while (cVar1 != '\0');

  return;

}





// --- FUN_004010a0 at 0x004010A0 (size: 40) ---


LONG __fastcall FUN_004010a0(undefined4 *param_1)



{

  LONG LVar1;

  

  LVar1 = InterlockedDecrement(param_1 + 1);

  if (LVar1 != 0) {

    return param_1[1];

  }

  if (param_1 != (undefined4 *)0x0) {

    (**(code **)*param_1)(1);

  }

  return 0;

}





// --- FUN_004010d0 at 0x004010D0 (size: 18) ---


bool FUN_004010d0(uint param_1,uint param_2)



{

  return (param_1 & param_2) == param_2;

}





// --- FUN_004010f0 at 0x004010F0 (size: 34) ---


void FUN_004010f0(int *param_1)



{

  if (param_1 != (int *)0x0) {

    (**(code **)(*param_1 + 0x20))();

    (**(code **)(*param_1 + 0x14))();

  }

  FUN_0054ba90();

  FUN_00555a20();

  return;

}





// --- FUN_00401120 at 0x00401120 (size: 54) ---


void FUN_00401120(void)



{

  FUN_00405fa0(0,0x80017);

  _control87(0x10000,0x30000);

  _control87(0,0x300);

  _control87(0,0x40000);

  return;

}





// --- FUN_00401160 at 0x00401160 (size: 67) ---


uint FUN_00401160(undefined4 param_1)



{

  int *piVar1;

  undefined *puVar2;

  undefined4 uVar3;

  uint *puVar4;

  uint local_8;

  int local_4;

  

  puVar4 = &local_8;

  uVar3 = 0;

  puVar2 = &DAT_00793840;

  piVar1 = &local_4;

  local_8 = 0;

  FUN_00406d10(piVar1,param_1,&DAT_00793840,0,&local_8);

  FUN_00406650(piVar1,param_1,puVar2,uVar3,puVar4);

  return (local_4 < 0) - 1 & local_8;

}





// --- FUN_004011b0 at 0x004011B0 (size: 34) ---


void __fastcall FUN_004011b0(int *param_1)



{

  LONG LVar1;

  undefined4 *puVar2;

  

  puVar2 = (undefined4 *)(*param_1 + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(*param_1 + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  return;

}





// --- FUN_004011e0 at 0x004011E0 (size: 149) ---


int * __thiscall FUN_004011e0(int *param_1,byte param_2)



{

  undefined4 *puVar1;

  LONG LVar2;

  int *piVar3;

  int local_4;

  

  if ((param_2 & 2) == 0) {

    puVar1 = (undefined4 *)*param_1;

    LVar2 = InterlockedDecrement(puVar1 + 1);

    if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

      (**(code **)*puVar1)(1);

    }

    if ((param_2 & 1) != 0) {

      operator_delete(param_1);

    }

    return param_1;

  }

  local_4 = param_1[-1];

  piVar3 = param_1 + local_4;

  if (-1 < local_4 + -1) {

    do {

      puVar1 = (undefined4 *)piVar3[-1];

      piVar3 = piVar3 + -1;

      LVar2 = InterlockedDecrement(puVar1 + 1);

      if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

        (**(code **)*puVar1)(1);

      }

      local_4 = local_4 + -1;

    } while (local_4 != 0);

  }

  if ((param_2 & 1) != 0) {

    operator_delete__(param_1 + -1);

  }

  return param_1 + -1;

}





// --- FUN_00401280 at 0x00401280 (size: 186) ---


undefined4 __thiscall FUN_00401280(int *param_1,uint param_2)



{

  undefined4 *puVar1;

  int iVar2;

  int iVar3;

  

  if (param_2 < 0x10) {

    iVar2 = 0;

    iVar3 = 0x24;

  }

  else {

    if (param_2 < 0x10001) {

      iVar3 = 0x1f;

      if (param_2 * 2 != 0) {

        for (; param_2 * 2 >> iVar3 == 0; iVar3 = iVar3 + -1) {

        }

      }

      iVar3 = 1 << ((char)iVar3 + 1U & 0x1f);

    }

    else {

      iVar3 = (param_2 & 0xffff0000) + 0x10000;

    }

    iVar2 = iVar3 + -0x10;

    if (iVar2 == 0) {

      iVar3 = 0x24;

    }

    else {

      iVar3 = iVar3 + 0x14;

    }

  }

  puVar1 = (undefined4 *)thunk_FUN_005df0f5(iVar3);

  if (puVar1 == (undefined4 *)0x0) {

    return 0;

  }

  puVar1[1] = 1;

  *puVar1 = &PTR_LAB_007cae34;

  puVar1[4] = 1;

  puVar1[2] = 1;

  puVar1[3] = 0xffffffff;

  *(undefined1 *)(puVar1 + 5) = 0;

  *param_1 = (int)(puVar1 + 5);

  *(uint *)(*param_1 + -4) = param_2 + 1;

  *(int *)(*param_1 + -0xc) = iVar2 + 0x10;

  return 1;

}





// --- FUN_00401340 at 0x00401340 (size: 88) ---


undefined4 * __thiscall FUN_00401340(undefined4 *param_1,char *param_2)



{

  char cVar1;

  char *pcVar2;

  LONG *lpAddend;

  

  if ((param_2 != (char *)0x0) && (*param_2 != '\0')) {

    pcVar2 = param_2;

    do {

      cVar1 = *pcVar2;

      pcVar2 = pcVar2 + 1;

    } while (cVar1 != '\0');

    FUN_00401280((int)pcVar2 - (int)(param_2 + 1));

    pcVar2 = (char *)*param_1;

    do {

      cVar1 = *param_2;

      param_2 = param_2 + 1;

      *pcVar2 = cVar1;

      pcVar2 = pcVar2 + 1;

    } while (cVar1 != '\0');

    return param_1;

  }

  lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

  *param_1 = PTR_DAT_00818344;

  InterlockedIncrement(lpAddend);

  return param_1;

}





// --- FUN_004013a0 at 0x004013A0 (size: 489) ---


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

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

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

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



undefined4 FUN_004013a0(void)



{

  char cVar1;

  int *piVar2;

  

  cVar1 = FUN_00406300();

  if (cVar1 == '\0') {

    FUN_00555810();

    FUN_005557a0();

    return 1;

  }

  FUN_00406d60();

  GetCommandLineA();

  cVar1 = thunk_FUN_004096b0();

  if (cVar1 == '\0') {

    FUN_00406f90();

    return 1;

  }

  FUN_00401120();

  DAT_00837720 = 0x40000001;

  FUN_00413850(0,&PTR_DAT_008183b4);

  FUN_0055af00();

  FUN_00555990(uRam00000000);

  FUN_00558230();

  piVar2 = (int *)FUN_00401160(&DAT_007936b8);

  if (piVar2 == (int *)0x0) {

    FUN_0054ba90();

    FUN_00555a20();

  }

  else {

    cVar1 = (**(code **)(piVar2[1] + 0x10))(0,0,1);

    if (cVar1 == '\0') {

      FUN_004010f0(piVar2);

    }

    else {

      FUN_00401340("Asheron\'s Call");

      cVar1 = (**(code **)(*piVar2 + 0x1c))(&stack0xffffffd8,1,1);

      if (cVar1 != '\0') {

        (**(code **)(*piVar2 + 0x2c))();

        FUN_004010f0(piVar2);

        FUN_004011b0();

        FUN_004020c0();

        FUN_00406f90();

        return 0;

      }

      FUN_004010f0(piVar2);

      FUN_004011b0();

      FUN_004020c0();

    }

  }

  FUN_00406f90();

  return 1;

}





// --- FUN_00401590 at 0x00401590 (size: 76) ---


void FUN_00401590(undefined4 *param_1,uint param_2,int param_3)



{

  undefined4 *puVar1;

  uint uVar2;

  

  puVar1 = (undefined4 *)FUN_0040acf0(param_2);

  if (puVar1 != (undefined4 *)0x0) {

    if ((*(byte *)(param_3 + 4) & 1) != 0) {

      for (uVar2 = param_2 >> 2; uVar2 != 0; uVar2 = uVar2 - 1) {

        *puVar1 = *param_1;

        param_1 = param_1 + 1;

        puVar1 = puVar1 + 1;

      }

      for (param_2 = param_2 & 3; param_2 != 0; param_2 = param_2 - 1) {

        *(undefined1 *)puVar1 = *(undefined1 *)param_1;

        param_1 = (undefined4 *)((int)param_1 + 1);

        puVar1 = (undefined4 *)((int)puVar1 + 1);

      }

      return;

    }

    for (uVar2 = param_2 >> 2; uVar2 != 0; uVar2 = uVar2 - 1) {

      *param_1 = *puVar1;

      puVar1 = puVar1 + 1;

      param_1 = param_1 + 1;

    }

    for (param_2 = param_2 & 3; param_2 != 0; param_2 = param_2 - 1) {

      *(undefined1 *)param_1 = *(undefined1 *)puVar1;

      puVar1 = (undefined4 *)((int)puVar1 + 1);

      param_1 = (undefined4 *)((int)param_1 + 1);

    }

  }

  return;

}





// --- FUN_00401600 at 0x00401600 (size: 85) ---


undefined4 * __fastcall FUN_00401600(undefined4 *param_1)



{

  undefined4 uVar1;

  

  *param_1 = &PTR_FUN_00793b3c;

  param_1[1] = 0;

  param_1[2] = 0;

  FUN_00406d60();

  param_1[6] = 0;

  param_1[7] = 0;

  param_1[8] = 0;

  *param_1 = &PTR_FUN_00793b50;

  uVar1 = FUN_00406d60();

  FUN_0040afb0(&PTR_PTR_008183b8,uVar1);

  FUN_00406f90();

  return param_1;

}





// --- FUN_004016b0 at 0x004016B0 (size: 66) ---


uint FUN_004016b0(char *param_1)



{

  uint uVar1;

  char cVar2;

  

  cVar2 = *param_1;

  uVar1 = 0;

  if (cVar2 != '\0') {

    do {

      uVar1 = uVar1 * 0x10 + (int)cVar2;

      if ((uVar1 & 0xf0000000) != 0) {

        uVar1 = ((uVar1 & 0xf0000000) >> 0x18 ^ uVar1) & 0xfffffff;

      }

      cVar2 = param_1[1];

      param_1 = param_1 + 1;

    } while (cVar2 != '\0');

    if (uVar1 == 0xffffffff) {

      uVar1 = 0xfffffffe;

    }

  }

  return uVar1;

}





// --- FUN_00401700 at 0x00401700 (size: 69) ---


void __thiscall FUN_00401700(int *param_1,int *param_2)



{

  int iVar1;

  LONG LVar2;

  

  iVar1 = *param_1;

  if (iVar1 != *param_2) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = *param_2;

    *param_1 = iVar1;

                    /* WARNING: Could not recover jumptable at 0x0040173a. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

    return;

  }

  return;

}





// --- FUN_00401750 at 0x00401750 (size: 47) ---


void FUN_00401750(void)



{

  int iVar1;

  

  if (DAT_008380c8 == 0) {

    iVar1 = FUN_005df0f5(0x8100);

    if (iVar1 != 0) {

      DAT_008380c8 = FUN_00433d20();

      return;

    }

    DAT_008380c8 = 0;

  }

  return;

}





// --- FUN_004017c0 at 0x004017C0 (size: 22) ---


void __fastcall FUN_004017c0(int param_1)



{

  (**(code **)(**(int **)(param_1 + 0x118) + 0x20))();

  FUN_00411fa0();

  return;

}





// --- FUN_004017e0 at 0x004017E0 (size: 287) ---


void FUN_004017e0(void)



{

  FUN_005def70(&DAT_008375b0);

  FUN_005def70(&DAT_008375b4);

  FUN_005def70(&DAT_008375b8);

  FUN_005def70(&DAT_008375bc);

  FUN_005def70(&DAT_008375c0);

  FUN_005def70(&DAT_008375c4);

  FUN_005def70(&DAT_008375c8);

  FUN_005def70(&DAT_008375cc);

  FUN_005def70(&DAT_008375dc);

  FUN_005def70(&DAT_008375d8);

  FUN_005def70(&DAT_008375e0);

  FUN_005def70(&DAT_008375e8);

  FUN_005def70(&DAT_0083761c);

  FUN_005def70(&DAT_008375f0);

  FUN_005def70(&DAT_008375f4);

  FUN_005def70(&DAT_008375f8);

  FUN_005def70(&DAT_008375fc);

  FUN_005def70(&DAT_00837600);

  FUN_005def70(&DAT_00837598);

  FUN_005def70(&DAT_008375a0);

  FUN_005def70(&DAT_00837594);

  FUN_005def70(&DAT_00837688);

  FUN_005def70(&DAT_00837690);

  FUN_005def70(&DAT_008375a4);

  FUN_005def70(&DAT_008375a8);

  FUN_005def70(&DAT_008375ac);

  FUN_005def70(&DAT_00837564);

  FUN_005def70(&DAT_00837568);

  return;

}





// --- FUN_00401920 at 0x00401920 (size: 119) ---


uint __thiscall FUN_00401920(undefined4 *param_1,undefined4 *param_2)



{

  byte bVar1;

  byte *pbVar2;

  int iVar3;

  byte *pbVar4;

  bool bVar5;

  

  pbVar4 = (byte *)*param_2;

  pbVar2 = (byte *)*param_1;

  if (*(int *)(pbVar2 + -4) == *(int *)(pbVar4 + -4)) {

    if (((*(int *)(pbVar2 + -8) == *(int *)(pbVar4 + -8)) || (*(int *)(pbVar2 + -8) == -1)) ||

       (*(int *)(pbVar4 + -8) == -1)) {

      while( true ) {

        bVar1 = *pbVar2;

        bVar5 = bVar1 < *pbVar4;

        if (bVar1 != *pbVar4) break;

        if (bVar1 == 0) {

          return 1;

        }

        bVar1 = pbVar2[1];

        bVar5 = bVar1 < pbVar4[1];

        if (bVar1 != pbVar4[1]) break;

        pbVar2 = pbVar2 + 2;

        pbVar4 = pbVar4 + 2;

        if (bVar1 == 0) {

          return 1;

        }

      }

      iVar3 = (1 - (uint)bVar5) - (uint)(bVar5 != 0);

      return CONCAT31((int3)((uint)iVar3 >> 8),iVar3 == 0);

    }

  }

  return (uint)pbVar2 & 0xffffff00;

}





// --- FUN_004019a0 at 0x004019A0 (size: 49) ---


void FUN_004019a0(undefined1 *param_1,int param_2)



{

  undefined1 *puVar1;

  

  FUN_0040ad10(1);

  puVar1 = (undefined1 *)FUN_0040acf0(1);

  if (puVar1 != (undefined1 *)0x0) {

    if ((*(byte *)(param_2 + 4) & 1) != 0) {

      *puVar1 = *param_1;

      return;

    }

    *param_1 = *puVar1;

  }

  return;

}





// --- FUN_004019e0 at 0x004019E0 (size: 53) ---


void FUN_004019e0(undefined2 *param_1,int param_2)



{

  undefined2 *puVar1;

  

  FUN_0040ad10(2);

  puVar1 = (undefined2 *)FUN_0040acf0(2);

  if (puVar1 != (undefined2 *)0x0) {

    if ((*(byte *)(param_2 + 4) & 1) != 0) {

      *puVar1 = *param_1;

      return;

    }

    *param_1 = *puVar1;

  }

  return;

}





// --- FUN_00401a20 at 0x00401A20 (size: 20) ---


undefined4 FUN_00401a20(int param_1)



{

  undefined4 uVar1;

  

  if (param_1 != 0) {

    uVar1 = FUN_004016b0();

    return uVar1;

  }

  return 0;

}





// --- FUN_00401a40 at 0x00401A40 (size: 26) ---


undefined4 * __fastcall FUN_00401a40(undefined4 *param_1)



{

  LONG *lpAddend;

  

  lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

  *param_1 = PTR_DAT_00818344;

  InterlockedIncrement(lpAddend);

  return param_1;

}





// --- FUN_00401a60 at 0x00401A60 (size: 26) ---


undefined4 * __fastcall FUN_00401a60(undefined4 *param_1)



{

  LONG *lpAddend;

  

  lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

  *param_1 = PTR_DAT_00818340;

  InterlockedIncrement(lpAddend);

  return param_1;

}





// --- FUN_00401a80 at 0x00401A80 (size: 362) ---


void FUN_00401a80(undefined4 param_1,uint *param_2,uint param_3)



{

  uint uVar1;

  undefined1 *puVar2;

  byte *pbVar3;

  uint uVar4;

  ushort local_8 [2];

  uint local_4;

  

  uVar1 = param_3;

  if ((*(byte *)(param_3 + 4) & 1) == 0) {

    if ((~*(byte *)(param_3 + 4) & 1) != 0) {

      FUN_0040ad10(1);

      pbVar3 = (byte *)FUN_0040acf0(1);

      if (pbVar3 == (byte *)0x0) {

        uVar4 = param_3 & 0xff;

      }

      else if ((*(byte *)(uVar1 + 4) & 1) == 0) {

        uVar4 = (uint)*pbVar3;

      }

      else {

        uVar4 = param_3 & 0xff;

        *pbVar3 = (byte)param_3;

      }

      if ((char)uVar4 < '\0') {

        FUN_004019a0(&param_3,uVar1);

        if ((uVar4 & 0x40) != 0) {

          FUN_004019e0(local_8,uVar1);

          *param_2 = ((uVar4 & 0x3f) << 8 | param_3 & 0xff) << 0x10 | (uint)local_8[0];

          return;

        }

        *param_2 = (uVar4 & 0x7f) << 8 | param_3 & 0xff;

        return;

      }

      *param_2 = uVar4;

    }

  }

  else {

    local_4 = *param_2;

    if (0x7f < local_4) {

      if (local_4 < 0x4000) {

        param_3 = CONCAT31(param_3._1_3_,*(undefined1 *)((int)param_2 + 1)) | 0x80;

        local_8[0] = CONCAT11(local_8[0]._1_1_,(char)*param_2);

        FUN_004019a0(&param_3,uVar1);

        FUN_004019a0(local_8,uVar1);

        return;

      }

      param_3 = CONCAT31(param_3._1_3_,(char)(local_4 >> 0x18)) | 0xc0;

      local_8[0] = CONCAT11(local_8[0]._1_1_,(char)(local_4 >> 0x10));

      FUN_004019a0(&param_3,uVar1);

      FUN_004019a0(local_8,uVar1);

      FUN_004019e0(&local_4,uVar1);

      return;

    }

    FUN_0040ad10(1);

    puVar2 = (undefined1 *)FUN_0040acf0(1);

    if ((puVar2 != (undefined1 *)0x0) && ((*(byte *)(uVar1 + 4) & 1) != 0)) {

      *puVar2 = (char)local_4;

      return;

    }

  }

  return;

}





// --- FUN_00401c50 at 0x00401C50 (size: 301) ---


void __fastcall FUN_00401c50(undefined4 *param_1)



{

  LONG LVar1;

  undefined4 *puVar2;

  

  puVar2 = (undefined4 *)(param_1[0x4f] + -0x14);

  param_1[-7] = &PTR_LAB_00793c48;

  param_1[-6] = &PTR_LAB_00793bf8;

  *param_1 = &PTR_FUN_00793bec;

  param_1[2] = &PTR_LAB_00793be0;

  param_1[3] = &PTR_LAB_00793bd0;

  param_1[0x47] = &PTR_FUN_00793b70;

  LVar1 = InterlockedDecrement((LONG *)(param_1[0x4f] + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  puVar2 = (undefined4 *)(param_1[0x4e] + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(param_1[0x4e] + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  puVar2 = (undefined4 *)(param_1[0x4d] + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(param_1[0x4d] + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  puVar2 = (undefined4 *)(param_1[0x4c] + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(param_1[0x4c] + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  puVar2 = (undefined4 *)(param_1[0x4a] + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(param_1[0x4a] + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  puVar2 = (undefined4 *)(param_1[0x49] + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(param_1[0x49] + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  puVar2 = (undefined4 *)(param_1[0x48] + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(param_1[0x48] + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  FUN_0043c610();

  FUN_00412b70();

  return;

}





// --- FUN_00401db0 at 0x00401DB0 (size: 7) ---


undefined4 __fastcall FUN_00401db0(int param_1)



{

  return *(undefined4 *)(param_1 + 0x94);

}





// --- FUN_00401dc0 at 0x00401DC0 (size: 13) ---


void __thiscall FUN_00401dc0(int param_1,undefined4 param_2)



{

  *(undefined4 *)(param_1 + 0x94) = param_2;

  return;

}





// --- FUN_00401e70 at 0x00401E70 (size: 37) ---


int __fastcall FUN_00401e70(int param_1)



{

  int iVar1;

  

  iVar1 = FUN_00401ea0();

  if ((iVar1 == 0) && (param_1 != 0)) {

    (*(code *)**(undefined4 **)(param_1 + 0x1c))(1);

  }

  return iVar1;

}





// --- FUN_00401ea0 at 0x00401EA0 (size: 23) ---


LONG __fastcall FUN_00401ea0(int param_1)



{

  LONG LVar1;

  

  LVar1 = InterlockedDecrement((LONG *)(param_1 + 4));

  if (LVar1 != 0) {

    return *(LONG *)(param_1 + 4);

  }

  return 0;

}





// --- FUN_00402000 at 0x00402000 (size: 17) ---


undefined4 FUN_00402000(undefined4 param_1)



{

  FUN_00413180(param_1);

  return param_1;

}





// --- FUN_00402020 at 0x00402020 (size: 77) ---


void __thiscall FUN_00402020(int param_1,int *param_2)



{

  int iVar1;

  LONG LVar2;

  

  iVar1 = *(int *)(param_1 + 0x144);

  if (iVar1 != *param_2) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = *param_2;

    *(int *)(param_1 + 0x144) = iVar1;

                    /* WARNING: Could not recover jumptable at 0x00402062. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

    return;

  }

  return;

}





// --- FUN_00402070 at 0x00402070 (size: 66) ---


int * __thiscall FUN_00402070(int *param_1,int *param_2)



{

  int iVar1;

  LONG LVar2;

  

  iVar1 = *param_1;

  if (iVar1 != *param_2) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = *param_2;

    *param_1 = iVar1;

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

  }

  return param_1;

}





// --- FUN_004020c0 at 0x004020C0 (size: 25) ---


void __fastcall FUN_004020c0(undefined4 *param_1)



{

  if ((param_1[1] & 0x80000000) == 0x80000000) {

    operator_delete__((void *)*param_1);

  }

  return;

}





// --- FUN_004020e0 at 0x004020E0 (size: 126) ---


void __thiscall

FUN_004020e0(int param_1,int *param_2,undefined4 param_3,undefined4 param_4,undefined4 param_5,

            undefined4 param_6,undefined4 param_7)



{

  int *piVar1;

  char cVar2;

  int iVar3;

  

  piVar1 = param_2;

  if (param_1 != 0) {

    FUN_004369a0(param_1,0xd,param_2,param_3,param_4,param_5,param_6,param_7);

  }

  if (DAT_008380c8 == 0) {

    iVar3 = FUN_005df0f5(0x8100);

    if (iVar3 == 0) {

      DAT_008380c8 = 0;

    }

    else {

      DAT_008380c8 = FUN_00433d20();

    }

  }

  cVar2 = FUN_00433710(piVar1,&param_2);

  if ((cVar2 != '\0') && (iVar3 = (**(code **)(*param_2 + 0x44))(), iVar3 != 0)) {

    *(undefined1 *)(iVar3 + 0x28) = 1;

  }

  return;

}





// --- FUN_00402160 at 0x00402160 (size: 126) ---


void __thiscall

FUN_00402160(int param_1,int *param_2,undefined4 param_3,undefined4 param_4,undefined4 param_5,

            undefined4 param_6,undefined4 param_7)



{

  int *piVar1;

  char cVar2;

  int iVar3;

  

  piVar1 = param_2;

  if (param_1 != 0) {

    FUN_004369a0(param_1,4,param_2,param_3,param_4,param_5,param_6,param_7);

  }

  if (DAT_008380c8 == 0) {

    iVar3 = FUN_005df0f5(0x8100);

    if (iVar3 == 0) {

      DAT_008380c8 = 0;

    }

    else {

      DAT_008380c8 = FUN_00433d20();

    }

  }

  cVar2 = FUN_00433710(piVar1,&param_2);

  if ((cVar2 != '\0') && (iVar3 = (**(code **)(*param_2 + 0x44))(), iVar3 != 0)) {

    *(undefined1 *)(iVar3 + 0x28) = 1;

  }

  return;

}





// --- FUN_004021e0 at 0x004021E0 (size: 77) ---


void __thiscall FUN_004021e0(int param_1,int *param_2)



{

  int iVar1;

  LONG LVar2;

  

  iVar1 = *(int *)(param_1 + 0x8c);

  if (iVar1 != *param_2) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = *param_2;

    *(int *)(param_1 + 0x8c) = iVar1;

                    /* WARNING: Could not recover jumptable at 0x00402222. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

    return;

  }

  return;

}





// --- FUN_00402230 at 0x00402230 (size: 77) ---


void __thiscall FUN_00402230(int param_1,int *param_2)



{

  int iVar1;

  LONG LVar2;

  

  iVar1 = *(int *)(param_1 + 0xa8);

  if (iVar1 != *param_2) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = *param_2;

    *(int *)(param_1 + 0xa8) = iVar1;

                    /* WARNING: Could not recover jumptable at 0x00402272. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

    return;

  }

  return;

}





// --- FUN_00402280 at 0x00402280 (size: 71) ---


void __fastcall FUN_00402280(int param_1)



{

  LONG LVar1;

  undefined4 *puVar2;

  

  puVar2 = (undefined4 *)(*(int *)(param_1 + 0xc) + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(*(int *)(param_1 + 0xc) + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  puVar2 = (undefined4 *)(*(int *)(param_1 + 8) + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(*(int *)(param_1 + 8) + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  return;

}





// --- FUN_004022d0 at 0x004022D0 (size: 189) ---


undefined4 __thiscall FUN_004022d0(int *param_1,uint param_2)



{

  undefined4 *puVar1;

  int iVar2;

  int iVar3;

  

  if (param_2 < 0x10) {

    iVar2 = 0;

    iVar3 = 0x34;

  }

  else {

    if (param_2 < 0x10001) {

      iVar3 = 0x1f;

      if (param_2 * 2 != 0) {

        for (; param_2 * 2 >> iVar3 == 0; iVar3 = iVar3 + -1) {

        }

      }

      iVar3 = 1 << ((char)iVar3 + 1U & 0x1f);

    }

    else {

      iVar3 = (param_2 & 0xffff0000) + 0x10000;

    }

    iVar2 = iVar3 + -0x10;

    if (iVar2 == 0) {

      iVar3 = 0x34;

    }

    else {

      iVar3 = iVar3 + 0x24 + iVar2;

    }

  }

  puVar1 = (undefined4 *)thunk_FUN_005df0f5(iVar3);

  if (puVar1 == (undefined4 *)0x0) {

    return 0;

  }

  puVar1[1] = 1;

  *puVar1 = &PTR_LAB_007cae34;

  puVar1[4] = 1;

  puVar1[2] = 1;

  puVar1[3] = 0xffffffff;

  *(undefined2 *)(puVar1 + 5) = 0;

  *param_1 = (int)(puVar1 + 5);

  *(uint *)(*param_1 + -4) = param_2 + 1;

  *(int *)(*param_1 + -0xc) = iVar2 + 0x10;

  return 1;

}





// --- FUN_00402390 at 0x00402390 (size: 97) ---


int __thiscall FUN_00402390(int *param_1,char *param_2,va_list param_3)



{

  int iVar1;

  int iVar2;

  LONG LVar3;

  undefined4 *puVar4;

  

  iVar2 = _vscprintf(param_2,param_3);

  iVar1 = *param_1;

  puVar4 = (undefined4 *)(iVar1 + -0x14);

  FUN_00401280(iVar2);

  _vsnprintf((char *)*param_1,iVar2 + 1,param_2,param_3);

  LVar3 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

  if ((LVar3 == 0) && (puVar4 != (undefined4 *)0x0)) {

    (**(code **)*puVar4)(1);

  }

  return iVar2;

}





// --- FUN_00402400 at 0x00402400 (size: 136) ---


void __thiscall FUN_00402400(int *param_1,uint param_2)



{

  uint uVar1;

  uint uVar2;

  uint uVar3;

  

  uVar1 = param_2;

  if ((*(byte *)(param_2 + 4) & 1) != 0) {

    param_2 = *(int *)(*param_1 + -4) - 1;

  }

  FUN_00401a80(&param_2,&param_2,uVar1);

  uVar2 = param_2;

  if ((*(uint *)(uVar1 + 4) >> 2 & 1) == 0) {

    if ((~*(byte *)(uVar1 + 4) & 1) != 0) {

      uVar3 = FUN_0040a8f0();

      if (uVar3 < uVar2) {

        FUN_0040aa50();

        return;

      }

      FUN_004010a0();

      FUN_00401280(uVar2);

      *(undefined1 *)(uVar2 + *param_1) = 0;

    }

    FUN_00401590(*param_1,uVar2,uVar1);

  }

  return;

}





// --- FUN_00402490 at 0x00402490 (size: 137) ---


void __thiscall FUN_00402490(int *param_1,wchar_t *param_2,size_t param_3)



{

  uint uVar1;

  wchar_t *_Source;

  int iVar2;

  

  if (((param_2 != (wchar_t *)0x0) && (*param_2 != L'\0')) && (param_3 != 0)) {

    _Source = (wchar_t *)*param_1;

    iVar2 = *(int *)(_Source + -2);

    uVar1 = iVar2 + param_3;

    if ((*(int *)(_Source + -8) == 1) && (uVar1 <= *(uint *)(_Source + -6))) {

      *(uint *)(_Source + -2) = uVar1;

      *(undefined4 *)(*param_1 + -8) = 0xffffffff;

    }

    else {

      FUN_004022d0(uVar1 - 1);

      wcscpy((wchar_t *)*param_1,_Source);

      FUN_004010a0();

    }

    wcsncpy((wchar_t *)(*param_1 + -2 + iVar2 * 2),param_2,param_3);

    *(undefined2 *)(*param_1 + -2 + *(int *)(*param_1 + -4) * 2) = 0;

  }

  return;

}





// --- FUN_00402520 at 0x00402520 (size: 97) ---


int __thiscall FUN_00402520(int *param_1,wchar_t *param_2,va_list param_3)



{

  int iVar1;

  int iVar2;

  LONG LVar3;

  undefined4 *puVar4;

  

  iVar2 = _vscwprintf(param_2,param_3);

  iVar1 = *param_1;

  puVar4 = (undefined4 *)(iVar1 + -0x14);

  FUN_004022d0(iVar2);

  _vsnwprintf((wchar_t *)*param_1,iVar2 + 1,param_2,param_3);

  LVar3 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

  if ((LVar3 == 0) && (puVar4 != (undefined4 *)0x0)) {

    (**(code **)*puVar4)(1);

  }

  return iVar2;

}





// --- FUN_00402630 at 0x00402630 (size: 34) ---


int __thiscall FUN_00402630(int param_1,byte param_2)



{

  FUN_00401c50();

  if ((param_2 & 1) != 0) {

    operator_delete((void *)(param_1 + -0x1c));

  }

  return param_1 + -0x1c;

}





// --- FUN_00402660 at 0x00402660 (size: 175) ---


undefined1

FUN_00402660(undefined4 param_1,undefined1 param_2,int *param_3,int *param_4,undefined4 param_5,

            undefined4 param_6,undefined4 param_7)



{

  undefined1 uVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined4 local_1c;

  undefined1 local_18;

  int local_14;

  int local_10;

  undefined4 local_c;

  undefined4 local_8;

  undefined4 local_4;

  

  local_1c = param_1;

  local_14 = *param_3;

  local_18 = param_2;

  InterlockedIncrement((LONG *)(local_14 + -0x10));

  local_10 = *param_4;

  InterlockedIncrement((LONG *)(local_10 + -0x10));

  local_c = param_5;

  local_8 = param_6;

  local_4 = param_7;

  uVar1 = FUN_0040a0d0(&local_1c);

  puVar3 = (undefined4 *)(local_10 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(local_10 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  puVar3 = (undefined4 *)(local_14 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(local_14 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return uVar1;

}





// --- FUN_00402710 at 0x00402710 (size: 20) ---


void FUN_00402710(undefined4 param_1,undefined4 param_2)



{

  FUN_00402390(param_2,&stack0x0000000c);

  return;

}





// --- FUN_00402730 at 0x00402730 (size: 83) ---


undefined4 * __thiscall FUN_00402730(undefined4 *param_1,wchar_t *param_2)



{

  size_t sVar1;

  LONG *lpAddend;

  

  if ((param_2 != (wchar_t *)0x0) && (*param_2 != L'\0')) {

    sVar1 = wcslen(param_2);

    FUN_004022d0(sVar1);

    wcscpy((wchar_t *)*param_1,param_2);

    return param_1;

  }

  lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

  *param_1 = PTR_DAT_00818340;

  InterlockedIncrement(lpAddend);

  return param_1;

}





// --- FUN_00402790 at 0x00402790 (size: 25) ---


void FUN_00402790(int *param_1)



{

  int iVar1;

  

  iVar1 = *(int *)(*param_1 + -4);

  if (iVar1 != 1) {

    FUN_00402490(*param_1,iVar1 + -1);

  }

  return;

}





// --- FUN_004027b0 at 0x004027B0 (size: 20) ---


void FUN_004027b0(undefined4 param_1,undefined4 param_2)



{

  FUN_00402520(param_2,&stack0x0000000c);

  return;

}





// --- FUN_004027d0 at 0x004027D0 (size: 53) ---


int __fastcall FUN_004027d0(void *param_1)



{

  int iVar1;

  LONG LVar2;

  

  LVar2 = InterlockedDecrement((LONG *)((int)param_1 + 8));

  if ((LVar2 != 0) && (iVar1 = *(LONG *)((int)param_1 + 8), iVar1 != 0)) {

    return iVar1;

  }

  if (param_1 != (void *)0x0) {

    *(undefined ***)((int)param_1 + 4) = &PTR_LAB_00793b6c;

    operator_delete(param_1);

  }

  return 0;

}





// --- FUN_00402810 at 0x00402810 (size: 628) ---


undefined4 * __fastcall FUN_00402810(undefined4 *param_1)



{

  char cVar1;

  LONG LVar2;

  BOOL BVar3;

  size_t sVar4;

  LONG *pLVar5;

  wchar_t *pwVar6;

  undefined4 *puVar7;

  wchar_t *local_110;

  char local_109;

  undefined *local_108;

  CHAR local_104 [260];

  

  FUN_00412e50(0);

  param_1[0x4e] = &PTR_FUN_00801670;

  *param_1 = &PTR_LAB_00793c48;

  param_1[1] = &PTR_LAB_00793bf8;

  param_1[7] = &PTR_FUN_00793bec;

  param_1[9] = &PTR_LAB_00793be0;

  param_1[10] = &PTR_LAB_00793bd0;

  param_1[0x4e] = &PTR_FUN_00793b70;

  pLVar5 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[0x4f] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar5);

  pLVar5 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[0x50] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar5);

  pLVar5 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[0x51] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar5);

  *(undefined1 *)(param_1 + 0x52) = 0;

  pLVar5 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[0x53] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar5);

  pLVar5 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[0x54] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar5);

  pLVar5 = (LONG *)(PTR_DAT_00818340 + -0x10);

  param_1[0x55] = PTR_DAT_00818340;

  InterlockedIncrement(pLVar5);

  pLVar5 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[0x56] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar5);

  local_108 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  cVar1 = FUN_0040db30(&local_108);

  if (cVar1 != '\0') {

    local_110 = (wchar_t *)PTR_DAT_00818344;

    InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

    FUN_00402710(&local_110,"%s\\UserPreferences.ini",local_108);

    thunk_FUN_0040da10(&local_110,0);

    local_109 = FUN_0040b320(&local_110,0);

    if (local_109 != '\0') {

      FUN_00402070(&local_110);

    }

    pwVar6 = local_110 + -10;

    LVar2 = InterlockedDecrement((LONG *)(local_110 + -8));

    if ((LVar2 == 0) && (pwVar6 != (wchar_t *)0x0)) {

      (*(code *)**(undefined4 **)pwVar6)(1);

    }

    if (local_109 != '\0') goto LAB_004029d6;

  }

  BVar3 = SHGetSpecialFolderPathA((HWND)0x0,local_104,5,1);

  if (BVar3 != 0) {

    FUN_00402710(&local_108,"%s\\Asheron\'s Call",local_104);

    thunk_FUN_0040df20(&local_108);

    FUN_00402710(param_1 + 0x19,"%s\\UserPreferences.ini",local_108);

  }

LAB_004029d6:

  sVar4 = wcslen(L"http://acbm.turbinegames.com/IISAcBillingMigration/IISAcBillingMigration.dll?ac1"

                );

  FUN_004022d0(sVar4);

  wcscpy(local_110,

         L"http://acbm.turbinegames.com/IISAcBillingMigration/IISAcBillingMigration.dll?ac1");

  pwVar6 = (wchar_t *)param_1[0x55];

  if (pwVar6 != local_110) {

    LVar2 = InterlockedDecrement((LONG *)(pwVar6 + -8));

    if ((LVar2 == 0) && (pwVar6 + -10 != (wchar_t *)0x0)) {

      (*(code *)**(undefined4 **)(pwVar6 + -10))(1);

    }

    param_1[0x55] = local_110;

    InterlockedIncrement((LONG *)(local_110 + -8));

  }

  pwVar6 = local_110 + -10;

  LVar2 = InterlockedDecrement((LONG *)(local_110 + -8));

  if ((LVar2 == 0) && (pwVar6 != (wchar_t *)0x0)) {

    (*(code *)**(undefined4 **)pwVar6)(1);

  }

  FUN_00695670();

  puVar7 = (undefined4 *)(local_108 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(local_108 + -0x10));

  if ((LVar2 == 0) && (puVar7 != (undefined4 *)0x0)) {

    (**(code **)*puVar7)(1);

  }

  return param_1;

}





// --- FUN_00403350 at 0x00403350 (size: 310) ---


undefined4 * __thiscall FUN_00403350(int *param_1,undefined4 *param_2,undefined2 param_3)



{

  int iVar1;

  DWORD DVar2;

  DWORD DVar3;

  LONG LVar4;

  undefined4 *puVar5;

  wchar_t *pwVar6;

  undefined *local_4;

  

  local_4 = PTR_DAT_00818340;

  InterlockedIncrement((LONG *)(PTR_DAT_00818340 + -0x10));

  iVar1 = *(int *)(*param_1 + -4);

  if (iVar1 == 1) {

    *param_2 = local_4;

    InterlockedIncrement((LONG *)(local_4 + -0x10));

  }

  else {

    iVar1 = (*(code *)PTR_FUN_00837394)(param_3,0,*param_1,iVar1,0,0);

    if (iVar1 == 0) {

      DVar2 = GetLastError();

      DVar3 = GetLastError();

      pwVar6 = 

      L"Could not determine number of bytes needed to convert from codepage %hu! GetLastError %d (0x%08x)\n"

      ;

    }

    else {

      FUN_004022d0(iVar1);

      iVar1 = (*(code *)PTR_FUN_00837394)

                        (param_3,0,*param_1,*(undefined4 *)(*param_1 + -4),local_4,iVar1);

      if (iVar1 != 0) {

        *(int *)(local_4 + -4) = iVar1;

        *param_2 = local_4;

        InterlockedIncrement((LONG *)(local_4 + -0x10));

        puVar5 = (undefined4 *)(local_4 + -0x14);

        LVar4 = InterlockedDecrement((LONG *)(local_4 + -0x10));

        if (LVar4 != 0) {

          return param_2;

        }

        if (puVar5 == (undefined4 *)0x0) {

          return param_2;

        }

        (**(code **)*puVar5)(1);

        return param_2;

      }

      DVar2 = GetLastError();

      DVar3 = GetLastError();

      pwVar6 = L"Failed conversion from codepage %hu! GetLastError %d (0x%08x)\n";

    }

    FUN_004027b0(&local_4,pwVar6,param_3,DVar3,DVar2);

    *param_2 = local_4;

    InterlockedIncrement((LONG *)(local_4 + -0x10));

  }

  puVar5 = (undefined4 *)(local_4 + -0x14);

  LVar4 = InterlockedDecrement((LONG *)(local_4 + -0x10));

  if ((LVar4 == 0) && (puVar5 != (undefined4 *)0x0)) {

    (**(code **)*puVar5)(1);

    return param_2;

  }

  return param_2;

}





// --- FUN_004034c0 at 0x004034C0 (size: 155) ---


void __thiscall FUN_004034c0(int *param_1,char *param_2)



{

  char cVar1;

  undefined4 *puVar2;

  LONG LVar3;

  char *pcVar4;

  LONG *lpAddend;

  

  if ((param_2 == (char *)0x0) || (*param_2 == '\0')) {

    puVar2 = (undefined4 *)*param_1;

    if (puVar2 != DAT_008ef11c) {

      LVar3 = InterlockedDecrement(puVar2 + 1);

      if ((LVar3 == 0) && (puVar2 != (undefined4 *)0x0)) {

        (**(code **)*puVar2)(1);

      }

      lpAddend = DAT_008ef11c + 1;

      *param_1 = (int)DAT_008ef11c;

                    /* WARNING: Could not recover jumptable at 0x00403555. Too many branches */

                    /* WARNING: Treating indirect jump as call */

      InterlockedIncrement(lpAddend);

      return;

    }

  }

  else {

    puVar2 = (undefined4 *)*param_1;

    LVar3 = InterlockedDecrement(puVar2 + 1);

    if ((LVar3 == 0) && (puVar2 != (undefined4 *)0x0)) {

      (**(code **)*puVar2)(1);

    }

    pcVar4 = param_2;

    do {

      cVar1 = *pcVar4;

      pcVar4 = pcVar4 + 1;

    } while (cVar1 != '\0');

    FUN_00403560((int)pcVar4 - (int)(param_2 + 1));

    pcVar4 = (char *)(*param_1 + 0x14);

    do {

      cVar1 = *param_2;

      param_2 = param_2 + 1;

      *pcVar4 = cVar1;

      pcVar4 = pcVar4 + 1;

    } while (cVar1 != '\0');

  }

  return;

}





// --- FUN_00403560 at 0x00403560 (size: 114) ---


void __thiscall FUN_00403560(int *param_1,uint param_2)



{

  undefined4 *puVar1;

  uint uVar2;

  

  uVar2 = 1;

  do {

    uVar2 = uVar2 * 2;

  } while (uVar2 < param_2);

  puVar1 = (undefined4 *)thunk_FUN_005df0f5(uVar2 + 0x18);

  if (puVar1 != (undefined4 *)0x0) {

    puVar1[1] = 1;

    *puVar1 = &PTR_LAB_007cae34;

    puVar1[2] = 1;

    puVar1[3] = 1;

    puVar1[4] = 0xffffffff;

    *(undefined1 *)(puVar1 + 5) = 0;

    *param_1 = (int)puVar1;

    puVar1[2] = param_2 + 1;

    *(uint *)(*param_1 + 0xc) = uVar2 + 1;

    return;

  }

  *param_1 = 0;

  iRam00000008 = param_2 + 1;

  *(uint *)(*param_1 + 0xc) = uVar2 + 1;

  return;

}





// --- FUN_004036d0 at 0x004036D0 (size: 145) ---


void __thiscall FUN_004036d0(int *param_1,undefined4 *param_2,int *param_3)



{

  int iVar1;

  int *piVar2;

  int *piVar3;

  int *unaff_ESI;

  int *local_4;

  

  local_4 = param_1;

  if (param_3 == (int *)0x0) {

    FUN_00403770(0);

    *param_2 = 0x80004002;

    return;

  }

  iVar1 = *param_3;

  param_3 = (int *)0x0;

  piVar3 = (int *)(**(code **)(iVar1 + 0xc))(&local_4,&DAT_00793b20,&param_3);

  piVar2 = local_4;

  iVar1 = *piVar3;

  piVar3 = (int *)*param_1;

  if (iVar1 < 0) {

    if (piVar3 != (int *)0x0) {

      (**(code **)(*piVar3 + 0x14))();

    }

    *param_1 = 0;

    param_1[1] = 0;

    *unaff_ESI = iVar1;

    return;

  }

  if (piVar3 != (int *)0x0) {

    (**(code **)(*piVar3 + 0x14))();

  }

  *param_1 = (int)piVar2;

  param_1[1] = 0;

  *unaff_ESI = iVar1;

  return;

}





// --- FUN_00403770 at 0x00403770 (size: 50) ---


int * __thiscall FUN_00403770(int *param_1,int *param_2)



{

  int *piVar1;

  

  piVar1 = (int *)*param_1;

  if (piVar1 != param_2) {

    *param_1 = (int)param_2;

    if (param_2 != (int *)0x0) {

      (**(code **)(*param_2 + 0x10))();

    }

    if (piVar1 != (int *)0x0) {

      (**(code **)(*piVar1 + 0x14))();

    }

    param_1[1] = 0;

  }

  return param_1;

}





// --- FUN_004037b0 at 0x004037B0 (size: 4588) ---


void FUN_004037b0(void)



{

  char cVar1;

  undefined4 uVar2;

  undefined4 uVar3;

  void *local_60;

  uint local_5c;

  uint local_58;

  void *local_54;

  uint local_50;

  uint local_4c;

  void *local_48;

  uint local_44;

  uint local_40;

  void *local_3c;

  uint local_38;

  uint local_34;

  void *local_30;

  uint local_2c;

  uint local_28;

  void *local_24;

  uint local_20;

  uint local_1c;

  void *local_18;

  uint local_14;

  uint local_10;

  void *local_c;

  uint local_8;

  uint local_4;

  

  uVar2 = FUN_004016b0("ID_Sound_DisableSound_Help");

  uVar2 = FUN_004016b0("ID_Sound_DisableSound",uVar2);

  FUN_005dee50(&DAT_008375b0,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Sound_EffectVolume_Help");

  uVar2 = FUN_004016b0("ID_Sound_EffectVolume",uVar2);

  FUN_005dee50(&DAT_008375b4,3,0x10000003,uVar2);

  FUN_005de990(&DAT_008375b4,0,0x3f800000);

  uVar2 = FUN_004016b0("ID_Sound_DisableAmbientSound_Help");

  uVar2 = FUN_004016b0("ID_Sound_DisableAmbientSound",uVar2);

  FUN_005dee50(&DAT_008375b8,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Sound_AmbientVolume_Help");

  uVar2 = FUN_004016b0("ID_Sound_AmbientVolume",uVar2);

  FUN_005dee50(&DAT_008375bc,3,0x10000003,uVar2);

  FUN_005de990(&DAT_008375bc,0,0x3f800000);

  uVar2 = FUN_004016b0("ID_Sound_DisableInterfaceSound_Help");

  uVar2 = FUN_004016b0("ID_Sound_DisableInterfaceSound",uVar2);

  FUN_005dee50(&DAT_008375c0,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Sound_InterfaceVolume_Help");

  uVar2 = FUN_004016b0("ID_Sound_InterfaceVolume",uVar2);

  FUN_005dee50(&DAT_008375c4,3,0x10000003,uVar2);

  FUN_005de990(&DAT_008375c4,0,0x3f800000);

  uVar2 = FUN_004016b0("ID_Sound_SoundFeatures_Help");

  uVar2 = FUN_004016b0("ID_Sound_SoundFeatures",uVar2);

  FUN_005dee50(&DAT_008375c8,2,0x10000003,uVar2);

  local_c = (void *)0x0;

  local_8 = 0;

  local_4 = 0;

  uVar2 = FUN_004016b0("ID_Sound_Stereo");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_c + local_4 * 4) = uVar2;

    local_4 = local_4 + 1;

  }

  uVar2 = FUN_004016b0("ID_Sound_Mono");

  if (local_4 < (local_8 & 0x7fffffff)) {

LAB_0040399e:

    *(undefined4 *)((int)local_c + local_4 * 4) = uVar2;

    local_4 = local_4 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_8 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_0040399e;

  }

  FUN_005dea80(&DAT_008375c8,&local_c);

  uVar2 = FUN_004016b0("ID_Sound_NoFocusNoSound_Help");

  uVar2 = FUN_004016b0("ID_Sound_NoFocusNoSound",uVar2);

  FUN_005dee50(&DAT_008375cc,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Misc_TooltipDelay_Help");

  uVar2 = FUN_004016b0("ID_Misc_TooltipDelay",uVar2);

  FUN_005dee50(&DAT_008375dc,3,0x10000003,uVar2);

  FUN_005de990(&DAT_008375dc,0,0x41200000);

  uVar2 = FUN_004016b0("ID_Misc_TooltipEnable_Help");

  uVar2 = FUN_004016b0("ID_Misc_TooltipEnable",uVar2);

  FUN_005dee50(&DAT_008375d8,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_UI_ChatFontFace_Help");

  uVar2 = FUN_004016b0("ID_UI_ChatFontFace",uVar2);

  FUN_005dee50(&DAT_00837564,2,0x10000003,uVar2);

  local_30 = (void *)0x0;

  local_2c = 0;

  local_28 = 0;

  uVar2 = FUN_004016b0("ID_UI_Value_Arial");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_30 + local_28 * 4) = uVar2;

    local_28 = local_28 + 1;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_CourierNew");

  if (local_28 < (local_2c & 0x7fffffff)) {

LAB_00403afc:

    *(undefined4 *)((int)local_30 + local_28 * 4) = uVar2;

    local_28 = local_28 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_2c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403afc;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_PalatinoLinotype");

  if (local_28 < (local_2c & 0x7fffffff)) {

LAB_00403b44:

    *(undefined4 *)((int)local_30 + local_28 * 4) = uVar2;

    local_28 = local_28 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_2c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403b44;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_Tahoma");

  if (local_28 < (local_2c & 0x7fffffff)) {

LAB_00403b8c:

    *(undefined4 *)((int)local_30 + local_28 * 4) = uVar2;

    local_28 = local_28 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_2c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403b8c;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_TimesNewRoman");

  if (local_28 < (local_2c & 0x7fffffff)) {

LAB_00403bd4:

    *(undefined4 *)((int)local_30 + local_28 * 4) = uVar2;

    local_28 = local_28 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_2c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403bd4;

  }

  FUN_005dea80(&DAT_00837564,&local_30);

  uVar2 = FUN_004016b0("ID_UI_ChatFontSize_Help");

  uVar2 = FUN_004016b0("ID_UI_ChatFontSize",uVar2);

  FUN_005dee50(&DAT_00837568,2,0x10000003,uVar2);

  local_3c = (void *)0x0;

  local_38 = 0;

  local_34 = 0;

  uVar2 = FUN_004016b0("ID_UI_Value_Tiny");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_3c + local_34 * 4) = uVar2;

    local_34 = local_34 + 1;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_Small");

  if (local_34 < (local_38 & 0x7fffffff)) {

LAB_00403c9b:

    *(undefined4 *)((int)local_3c + local_34 * 4) = uVar2;

    local_34 = local_34 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_38 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403c9b;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_Medium");

  if (local_34 < (local_38 & 0x7fffffff)) {

LAB_00403ce3:

    *(undefined4 *)((int)local_3c + local_34 * 4) = uVar2;

    local_34 = local_34 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_38 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403ce3;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_Large");

  if (local_34 < (local_38 & 0x7fffffff)) {

LAB_00403d2b:

    *(undefined4 *)((int)local_3c + local_34 * 4) = uVar2;

    local_34 = local_34 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_38 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403d2b;

  }

  uVar2 = FUN_004016b0("ID_UI_Value_XLarge");

  if (local_34 < (local_38 & 0x7fffffff)) {

LAB_00403d73:

    *(undefined4 *)((int)local_3c + local_34 * 4) = uVar2;

    local_34 = local_34 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_38 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403d73;

  }

  FUN_005dea80(&DAT_00837568,&local_3c);

  uVar2 = FUN_004016b0("ID_Graphics_TextureFiltering_Help");

  uVar2 = FUN_004016b0("ID_Graphics_TextureFiltering",uVar2);

  FUN_005dee50(&DAT_008375e0,2,0x10000003,uVar2);

  local_24 = (void *)0x0;

  local_20 = 0;

  local_1c = 0;

  uVar2 = FUN_004016b0("ID_Graphics_TextureFiltering_Bilinear");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_24 + local_1c * 4) = uVar2;

    local_1c = local_1c + 1;

  }

  uVar2 = FUN_004016b0("ID_Graphics_TextureFiltering_Trilinear");

  if (local_1c < (local_20 & 0x7fffffff)) {

LAB_00403e3a:

    *(undefined4 *)((int)local_24 + local_1c * 4) = uVar2;

    local_1c = local_1c + 1;

  }

  else {

    uVar3 = FUN_00453850((local_20 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403e3a;

  }

  uVar2 = FUN_004016b0("ID_Graphics_TextureFiltering_Sharp");

  if (local_1c < (local_20 & 0x7fffffff)) {

LAB_00403e82:

    *(undefined4 *)((int)local_24 + local_1c * 4) = uVar2;

    local_1c = local_1c + 1;

  }

  else {

    uVar3 = FUN_00453850((local_20 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403e82;

  }

  uVar2 = FUN_004016b0("ID_Graphics_TextureFiltering_Anisotropic");

  if (local_1c < (local_20 & 0x7fffffff)) {

LAB_00403eca:

    *(undefined4 *)((int)local_24 + local_1c * 4) = uVar2;

    local_1c = local_1c + 1;

  }

  else {

    uVar3 = FUN_00453850((local_20 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403eca;

  }

  FUN_005dea80(&DAT_008375e0,&local_24);

  uVar2 = FUN_004016b0("ID_Graphics_BuildingDetailTextures_Help");

  uVar2 = FUN_004016b0("ID_Graphics_BuildingDetailTextures",uVar2);

  FUN_005dee50(&DAT_008375e8,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Graphics_MultiPassAlpha_Help");

  uVar2 = FUN_004016b0("ID_Graphics_MultiPassAlpha",uVar2);

  FUN_005dee50(&DAT_0083761c,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Graphics_LandscapeTextureDetail_Help");

  uVar2 = FUN_004016b0("ID_Graphics_LandscapeTextureDetail",uVar2);

  FUN_005dee50(&DAT_008375f0,2,0x10000003,uVar2);

  local_48 = (void *)0x0;

  local_44 = 0;

  local_40 = 0;

  uVar2 = FUN_004016b0("ID_Graphics_Value_VeryLow");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_48 + local_40 * 4) = uVar2;

    local_40 = local_40 + 1;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Low");

  if (local_40 < (local_44 & 0x7fffffff)) {

LAB_00403feb:

    *(undefined4 *)((int)local_48 + local_40 * 4) = uVar2;

    local_40 = local_40 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_44 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00403feb;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Medium");

  if (local_40 < (local_44 & 0x7fffffff)) {

LAB_00404033:

    *(undefined4 *)((int)local_48 + local_40 * 4) = uVar2;

    local_40 = local_40 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_44 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00404033;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_High");

  if (local_40 < (local_44 & 0x7fffffff)) {

LAB_0040407b:

    *(undefined4 *)((int)local_48 + local_40 * 4) = uVar2;

    local_40 = local_40 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_44 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_0040407b;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_VeryHigh");

  if (local_40 < (local_44 & 0x7fffffff)) {

LAB_004040c3:

    *(undefined4 *)((int)local_48 + local_40 * 4) = uVar2;

    local_40 = local_40 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_44 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_004040c3;

  }

  FUN_005dea80(&DAT_008375f0,&local_48);

  uVar2 = FUN_004016b0("ID_Graphics_EnvironmentTextureDetail_Help");

  uVar2 = FUN_004016b0("ID_Graphics_EnvironmentTextureDetail",uVar2);

  FUN_005dee50(&DAT_008375f4,2,0x10000003,uVar2);

  local_54 = (void *)0x0;

  local_50 = 0;

  local_4c = 0;

  uVar2 = FUN_004016b0("ID_Graphics_Value_VeryLow");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_54 + local_4c * 4) = uVar2;

    local_4c = local_4c + 1;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Low");

  if (local_4c < (local_50 & 0x7fffffff)) {

LAB_0040418a:

    *(undefined4 *)((int)local_54 + local_4c * 4) = uVar2;

    local_4c = local_4c + 1;

  }

  else {

    uVar3 = FUN_00453850((local_50 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_0040418a;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Medium");

  if (local_4c < (local_50 & 0x7fffffff)) {

LAB_004041d2:

    *(undefined4 *)((int)local_54 + local_4c * 4) = uVar2;

    local_4c = local_4c + 1;

  }

  else {

    uVar3 = FUN_00453850((local_50 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_004041d2;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_High");

  if (local_4c < (local_50 & 0x7fffffff)) {

LAB_0040421a:

    *(undefined4 *)((int)local_54 + local_4c * 4) = uVar2;

    local_4c = local_4c + 1;

  }

  else {

    uVar3 = FUN_00453850((local_50 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_0040421a;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_VeryHigh");

  if (local_4c < (local_50 & 0x7fffffff)) {

LAB_00404262:

    *(undefined4 *)((int)local_54 + local_4c * 4) = uVar2;

    local_4c = local_4c + 1;

  }

  else {

    uVar3 = FUN_00453850((local_50 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00404262;

  }

  FUN_005dea80(&DAT_008375f4,&local_54);

  uVar2 = FUN_004016b0("ID_Graphics_SceneryDrawDistance_Help");

  uVar2 = FUN_004016b0("ID_Graphics_SceneryDrawDistance",uVar2);

  FUN_005dee50(&DAT_008375f8,2,0x10000003,uVar2);

  local_18 = (void *)0x0;

  local_14 = 0;

  local_10 = 0;

  uVar2 = FUN_004016b0("ID_Graphics_Value_Low");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_18 + local_10 * 4) = uVar2;

    local_10 = local_10 + 1;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Medium");

  if (local_10 < (local_14 & 0x7fffffff)) {

LAB_00404329:

    *(undefined4 *)((int)local_18 + local_10 * 4) = uVar2;

    local_10 = local_10 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_14 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00404329;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_High");

  if (local_10 < (local_14 & 0x7fffffff)) {

LAB_00404371:

    *(undefined4 *)((int)local_18 + local_10 * 4) = uVar2;

    local_10 = local_10 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_14 & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00404371;

  }

  FUN_005dea80(&DAT_008375f8,&local_18);

  uVar2 = FUN_004016b0("ID_Graphics_LandscapeDrawDistance_Help");

  uVar2 = FUN_004016b0("ID_Graphics_LandscapeDrawDistance",uVar2);

  FUN_005dee50(&DAT_008375fc,2,0x10000003,uVar2);

  local_60 = (void *)0x0;

  local_5c = 0;

  local_58 = 0;

  uVar2 = FUN_004016b0("ID_Graphics_Value_VeryLow");

  uVar3 = FUN_00453850(1);

  cVar1 = FUN_004180a0(uVar3);

  if (cVar1 != '\0') {

    *(undefined4 *)((int)local_60 + local_58 * 4) = uVar2;

    local_58 = local_58 + 1;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Low");

  if (local_58 < (local_5c & 0x7fffffff)) {

LAB_00404438:

    *(undefined4 *)((int)local_60 + local_58 * 4) = uVar2;

    local_58 = local_58 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_5c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00404438;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Medium");

  if (local_58 < (local_5c & 0x7fffffff)) {

LAB_00404480:

    *(undefined4 *)((int)local_60 + local_58 * 4) = uVar2;

    local_58 = local_58 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_5c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00404480;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_High");

  if (local_58 < (local_5c & 0x7fffffff)) {

LAB_004044c8:

    *(undefined4 *)((int)local_60 + local_58 * 4) = uVar2;

    local_58 = local_58 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_5c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_004044c8;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_VeryHigh");

  if (local_58 < (local_5c & 0x7fffffff)) {

LAB_00404510:

    *(undefined4 *)((int)local_60 + local_58 * 4) = uVar2;

    local_58 = local_58 + 1;

  }

  else {

    uVar3 = FUN_00453850((local_5c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 != '\0') goto LAB_00404510;

  }

  uVar2 = FUN_004016b0("ID_Graphics_Value_Extreme");

  if ((local_5c & 0x7fffffff) <= local_58) {

    uVar3 = FUN_00453850((local_5c & 0x7fffffff) + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 == '\0') goto LAB_00404567;

  }

  *(undefined4 *)((int)local_60 + local_58 * 4) = uVar2;

  local_58 = local_58 + 1;

LAB_00404567:

  FUN_005dea80(&DAT_008375fc,&local_60);

  uVar2 = FUN_004016b0("ID_Graphics_FieldOfView_Help");

  uVar2 = FUN_004016b0("ID_Graphics_FieldOfView",uVar2);

  FUN_005dee50(&DAT_008375ec,3,0x10000003,uVar2);

  FUN_005de990(&DAT_008375ec,0x41200000,0x43200000);

  uVar2 = FUN_004016b0("ID_Graphics_ScreenBrightness_Help");

  uVar2 = FUN_004016b0("ID_Graphics_ScreenBrightness",uVar2);

  FUN_005dee50(&DAT_00837600,3,0x10000003,uVar2);

  FUN_005de990(&DAT_00837600,0xbf800000,0x3f800000);

  uVar2 = FUN_004016b0("ID_Graphics_AdaptiveDegrade_Help");

  uVar2 = FUN_004016b0("ID_Graphics_AdaptiveDegrade",uVar2);

  FUN_005dee50(&DAT_00837610,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Graphics_AdaptiveDegradeBias_Help");

  uVar2 = FUN_004016b0("ID_Graphics_AdaptiveDegradeBias",uVar2);

  FUN_005dee50(&DAT_00837614,3,0x10000003,uVar2);

  FUN_005de990(&DAT_00837614,0xbf800000,0x3f800000);

  uVar2 = FUN_004016b0("ID_Graphics_DegradeDistance_Help");

  uVar2 = FUN_004016b0("ID_Graphics_DegradeDistance",uVar2);

  FUN_005dee50(&DAT_00837618,3,0x10000003,uVar2);

  FUN_005de990(&DAT_00837618,0,0x42c80000);

  uVar2 = FUN_004016b0("ID_Rendering_FullScreen_Help");

  uVar2 = FUN_004016b0("ID_Rendering_FullScreen",uVar2);

  FUN_005dee50(&DAT_00837598,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Rendering_SyncToDisplayRefresh_Help");

  uVar2 = FUN_004016b0("ID_Rendering_SyncToDisplayRefresh",uVar2);

  FUN_005dee50(&DAT_008375a0,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Rendering_DisplayResolution_Help");

  uVar2 = FUN_004016b0("ID_Rendering_DisplayResolution",uVar2);

  FUN_005dee50(&DAT_00837594,2,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Rendering_RefreshRate_Help");

  uVar2 = FUN_004016b0("ID_Rendering_RefreshRate",uVar2);

  FUN_005dee50(&DAT_0083759c,2,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Input_MouseLookSensitivity_Help");

  uVar2 = FUN_004016b0("ID_Input_MouseLookSensitivity",uVar2);

  FUN_005dee50(&DAT_00837688,3,0x10000003,uVar2);

  FUN_005de990(&DAT_00837688,0x3c23d70a,0x3f800000);

  uVar2 = FUN_004016b0("ID_Input_InvertMouseLookYAxis_Help");

  uVar2 = FUN_004016b0("ID_Input_InvertMouseLookYAxis",uVar2);

  FUN_005dee50(&DAT_00837690,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Input_UseMouseTurning_Help");

  uVar2 = FUN_004016b0("ID_Input_UseMouseTurning",uVar2);

  FUN_005dee50(&DAT_00837694,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Camera_AlignToSlope_Help");

  uVar2 = FUN_004016b0("ID_Camera_AlignToSlope",uVar2);

  FUN_005dee50(&DAT_008375a4,4,0x10000003,uVar2);

  uVar2 = FUN_004016b0("ID_Camera_Stiffness_Help");

  uVar2 = FUN_004016b0("ID_Camera_Stiffness",uVar2);

  FUN_005dee50(&DAT_008375a8,3,0x10000003,uVar2);

  FUN_005de990(&DAT_008375a8,0x3e924925,0x3f800000);

  uVar2 = FUN_004016b0("ID_Camera_AdjustmentSpeed_Help");

  uVar2 = FUN_004016b0("ID_Camera_AdjustmentSpeed",uVar2);

  FUN_005dee50(&DAT_008375ac,3,0x10000003,uVar2);

  FUN_005de990(&DAT_008375ac,0x40a00000,0x42a00000);

  if ((local_5c & 0x80000000) == 0x80000000) {

    operator_delete__(local_60);

  }

  if ((local_14 & 0x80000000) == 0x80000000) {

    operator_delete__(local_18);

  }

  if ((local_50 & 0x80000000) == 0x80000000) {

    operator_delete__(local_54);

  }

  if ((local_44 & 0x80000000) == 0x80000000) {

    operator_delete__(local_48);

  }

  if ((local_20 & 0x80000000) == 0x80000000) {

    operator_delete__(local_24);

  }

  if ((local_38 & 0x80000000) == 0x80000000) {

    operator_delete__(local_3c);

  }

  if ((local_2c & 0x80000000) == 0x80000000) {

    operator_delete__(local_30);

  }

  if ((local_8 & 0x80000000) == 0x80000000) {

    operator_delete__(local_c);

  }

  return;

}





// --- FUN_00404a40 at 0x00404A40 (size: 148) ---


undefined4 * __thiscall FUN_00404a40(undefined4 *param_1,undefined4 param_2,int param_3)



{

  int iVar1;

  int *piVar2;

  LONG LVar3;

  LONG *lpAddend;

  undefined4 *puVar4;

  undefined4 *local_4;

  

  lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

  *param_1 = PTR_DAT_00818340;

  local_4 = param_1;

  InterlockedIncrement(lpAddend);

  FUN_00401340(param_3);

  piVar2 = (int *)FUN_00403350(&local_4,0);

  iVar1 = *(int *)(*piVar2 + -4);

  if (iVar1 != 1) {

    FUN_00402490(*piVar2,iVar1 + -1);

  }

  puVar4 = local_4 + -5;

  LVar3 = InterlockedDecrement(local_4 + -4);

  if ((LVar3 == 0) && (puVar4 != (undefined4 *)0x0)) {

    (**(code **)*puVar4)(1);

  }

  LVar3 = InterlockedDecrement((LONG *)(param_3 + -0x10));

  if ((LVar3 == 0) && ((undefined4 *)(param_3 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(param_3 + -0x14))(1);

  }

  return param_1;

}





// --- FUN_00404b40 at 0x00404B40 (size: 89) ---


int __thiscall FUN_00404b40(undefined4 *param_1,undefined4 *param_2,char param_3)



{

  byte bVar1;

  byte *pbVar2;

  int iVar3;

  byte *pbVar4;

  bool bVar5;

  

  if (param_3 == '\0') {

    iVar3 = _stricmp((char *)*param_1,(char *)*param_2);

    return iVar3;

  }

  pbVar4 = (byte *)*param_2;

  pbVar2 = (byte *)*param_1;

  while( true ) {

    bVar1 = *pbVar2;

    bVar5 = bVar1 < *pbVar4;

    if (bVar1 != *pbVar4) break;

    if (bVar1 == 0) {

      return 0;

    }

    bVar1 = pbVar2[1];

    bVar5 = bVar1 < pbVar4[1];

    if (bVar1 != pbVar4[1]) break;

    pbVar2 = pbVar2 + 2;

    pbVar4 = pbVar4 + 2;

    if (bVar1 == 0) {

      return 0;

    }

  }

  return (1 - (uint)bVar5) - (uint)(bVar5 != 0);

}





// --- FUN_00404ba0 at 0x00404BA0 (size: 298) ---


undefined4 * FUN_00404ba0(uint param_1,uint *param_2)



{

  int iVar1;

  undefined4 *puVar2;

  uint uVar3;

  uint uVar4;

  

  uVar3 = *param_2 * param_1;

  uVar4 = DAT_00837710 - (int)DAT_0083770c;

  puVar2 = DAT_0083770c;

  if (uVar4 < uVar3) {

    do {

      if (param_1 <= uVar4) {

        *param_2 = uVar4 / param_1;

        puVar2 = DAT_0083770c;

        DAT_0083770c = (undefined4 *)((int)DAT_0083770c + (uVar4 / param_1) * param_1);

        return puVar2;

      }

      iVar1 = ((DAT_00837708 >> 4) + 7 & 0xfffffff8) + uVar3 * 2;

      if (uVar4 != 0) {

        uVar3 = uVar4 - 1 >> 3;

        *DAT_0083770c = *(undefined4 *)(&DAT_008376c8 + uVar3 * 4);

        *(undefined4 **)(&DAT_008376c8 + uVar3 * 4) = DAT_0083770c;

      }

      DAT_0083770c = (undefined4 *)FUN_005df0f5(iVar1);

      uVar3 = param_1;

      if (DAT_0083770c == (undefined4 *)0x0) {

        for (; uVar3 < 0x81; uVar3 = uVar3 + 8) {

          uVar4 = uVar3 - 1 >> 3;

          puVar2 = *(undefined4 **)(&DAT_008376c8 + uVar4 * 4);

          if (puVar2 != (undefined4 *)0x0) {

            *(undefined4 *)(&DAT_008376c8 + uVar4 * 4) = *puVar2;

            DAT_00837710 = (int)puVar2 + uVar3;

            DAT_0083770c = puVar2;

            goto LAB_00404c6d;

          }

        }

        DAT_00837710 = 0;

        DAT_0083770c = (undefined4 *)FUN_005df0f5(iVar1);

      }

      DAT_00837708 = DAT_00837708 + iVar1;

      DAT_00837710 = (int)DAT_0083770c + iVar1;

LAB_00404c6d:

      uVar3 = *param_2 * param_1;

      uVar4 = DAT_00837710 - (int)DAT_0083770c;

      puVar2 = DAT_0083770c;

    } while (uVar4 < uVar3);

  }

  DAT_0083770c = (undefined4 *)((int)puVar2 + uVar3);

  return puVar2;

}





// --- FUN_00404cd0 at 0x00404CD0 (size: 65) ---


void __fastcall FUN_00404cd0(int *param_1)



{

  undefined *puVar1;

  LONG LVar2;

  LONG *lpAddend;

  

  puVar1 = (undefined *)*param_1;

  if (puVar1 != PTR_DAT_00818344) {

    LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(puVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar1 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *param_1 = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

  }

  return;

}





// --- FUN_00404d20 at 0x00404D20 (size: 23) ---


bool FUN_00404d20(undefined4 param_1,undefined4 param_2)



{

  int iVar1;

  

  iVar1 = FUN_00404b40(param_1,param_2);

  return iVar1 == 0;

}





// --- FUN_00404d40 at 0x00404D40 (size: 39) ---


int __thiscall FUN_00404d40(int *param_1,undefined4 *param_2)



{

  char *pcVar1;

  

  pcVar1 = strstr((char *)*param_1,(char *)*param_2);

  if (pcVar1 == (char *)0x0) {

    return -1;

  }

  return (int)pcVar1 - *param_1;

}





// --- FUN_00404d70 at 0x00404D70 (size: 31) ---


void __fastcall FUN_00404d70(undefined4 *param_1)



{

  char *_Str;

  int *piVar1;

  

  _Str = (char *)*param_1;

  piVar1 = _errno();

  *piVar1 = 0;

  strtoul(_Str,(char **)0x0,0);

  return;

}





// --- FUN_00404d90 at 0x00404D90 (size: 235) ---


void FUN_00404d90(LONG *param_1)



{

  uint uVar1;

  LONG LVar2;

  uint uVar3;

  uint uVar4;

  int iVar5;

  int iVar6;

  

  LVar2 = InterlockedExchange(param_1,1);

  uVar1 = DAT_00818298;

  if (LVar2 != 0) {

    uVar4 = 0;

    if (DAT_00818298 != 0) {

      uVar3 = DAT_00837714 >> 1;

      do {

        if (((uVar3 <= uVar4) && (*param_1 == 0)) &&

           (LVar2 = InterlockedExchange(param_1,1), LVar2 == 0)) {

          DAT_00818298 = 1000;

          DAT_00837714 = uVar4;

          return;

        }

        uVar4 = uVar4 + 1;

      } while (uVar4 < uVar1);

    }

    DAT_00818298 = 0x1e;

    iVar6 = 6;

    while( true ) {

      iVar5 = iVar6;

      if (0x1b < iVar6) {

        iVar5 = 0x1b;

      }

      LVar2 = InterlockedExchange(param_1,1);

      if (LVar2 == 0) break;

      if (iVar5 < 0x15) {

        Sleep(1);

        iVar6 = iVar6 + 1;

      }

      else {

        Sleep(1 << ((char)iVar5 - 0x14U & 0x1f));

        iVar6 = iVar6 + 1;

      }

    }

  }

  return;

}





// --- FUN_00404e80 at 0x00404E80 (size: 104) ---


void FUN_00404e80(int param_1)



{

  undefined4 *puVar1;

  int iVar2;

  undefined4 *puVar3;

  uint uVar4;

  int local_4;

  

  uVar4 = param_1 + 7U & 0xfffffff8;

  local_4 = 0x14;

  iVar2 = FUN_00404ba0(uVar4,&local_4);

  if (local_4 != 1) {

    puVar3 = (undefined4 *)(iVar2 + uVar4);

    *(undefined4 **)(&DAT_008376c8 + (uVar4 - 1 >> 3) * 4) = puVar3;

    iVar2 = 1;

    puVar1 = puVar3;

    if (local_4 != 2) {

      do {

        puVar3 = (undefined4 *)((int)puVar1 + uVar4);

        *puVar1 = puVar3;

        iVar2 = iVar2 + 1;

        puVar1 = puVar3;

      } while (local_4 + -1 != iVar2);

    }

    *puVar3 = 0;

  }

  return;

}





// --- FUN_00404ef0 at 0x00404EF0 (size: 133) ---


void __thiscall FUN_00404ef0(int *param_1,char *param_2,size_t param_3)



{

  uint uVar1;

  int iVar2;

  int iVar3;

  

  if (((param_2 != (char *)0x0) && (*param_2 != '\0')) && (param_3 != 0)) {

    iVar2 = *param_1;

    iVar3 = *(int *)(iVar2 + -4);

    uVar1 = iVar3 + param_3;

    if ((*(int *)(iVar2 + -0x10) == 1) && (uVar1 <= *(uint *)(iVar2 + -0xc))) {

      *(uint *)(iVar2 + -4) = uVar1;

      *(undefined4 *)(*param_1 + -8) = 0xffffffff;

    }

    else {

      FUN_00401280(uVar1 - 1);

      FUN_00401070(*param_1,iVar2);

      FUN_004010a0();

    }

    strncpy((char *)(*param_1 + -1 + iVar3),param_2,param_3);

    *(undefined1 *)(*(int *)(*param_1 + -4) + -1 + *param_1) = 0;

  }

  return;

}





// --- FUN_00404f80 at 0x00404F80 (size: 126) ---


undefined4 * __thiscall FUN_00404f80(int *param_1,undefined4 *param_2,uint param_3,uint param_4)



{

  int iVar1;

  undefined *puVar2;

  LONG LVar3;

  uint uVar4;

  

  puVar2 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  iVar1 = *(int *)(*param_1 + -4);

  uVar4 = iVar1 - 1;

  if (param_3 < uVar4) {

    if (uVar4 <= param_4) {

      param_4 = iVar1 - 2;

    }

    FUN_00404ef0(*param_1 + param_3,(param_4 - param_3) + 1);

  }

  *param_2 = puVar2;

  InterlockedIncrement((LONG *)(puVar2 + -0x10));

  LVar3 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

  if ((LVar3 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

  }

  return param_2;

}





// --- FUN_00405000 at 0x00405000 (size: 201) ---


void __thiscall FUN_00405000(uint *param_1,char *param_2)



{

  char cVar1;

  uint uVar2;

  char *pcVar3;

  uint uVar4;

  LONG LVar5;

  LONG *lpAddend;

  

  if ((param_2 == (char *)0x0) || (*param_2 == '\0')) {

    uVar2 = *param_1;

    if ((undefined *)(-(uint)(uVar2 != 0x14) & uVar2) != PTR_DAT_00818344) {

      LVar5 = InterlockedDecrement((LONG *)(uVar2 - 0x10));

      if ((LVar5 == 0) && ((undefined4 *)(uVar2 - 0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(uVar2 - 0x14))(1);

      }

      lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

      *param_1 = (uint)PTR_DAT_00818344;

                    /* WARNING: Could not recover jumptable at 0x004050c3. Too many branches */

                    /* WARNING: Treating indirect jump as call */

      InterlockedIncrement(lpAddend);

      return;

    }

  }

  else {

    pcVar3 = param_2;

    do {

      cVar1 = *pcVar3;

      pcVar3 = pcVar3 + 1;

    } while (cVar1 != '\0');

    uVar4 = (int)pcVar3 - (int)(param_2 + 1);

    uVar2 = *param_1;

    if ((*(int *)(uVar2 - 0x10) == 1) && (uVar4 < *(uint *)(uVar2 - 0xc))) {

      *(undefined4 *)(uVar2 - 8) = 0xffffffff;

      *(uint *)(*param_1 - 4) = uVar4 + 1;

    }

    else {

      LVar5 = InterlockedDecrement((LONG *)(uVar2 - 0x10));

      if ((LVar5 == 0) && ((undefined4 *)(uVar2 - 0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(uVar2 - 0x14))(1);

      }

      FUN_00401280(uVar4);

    }

    strncpy((char *)*param_1,param_2,uVar4 + 1);

  }

  return;

}





// --- FUN_004050d0 at 0x004050D0 (size: 77) ---


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



void FUN_004050d0(int param_1)



{

  int *piVar1;

  

  FUN_00404d90(&DAT_008376c0);

  piVar1 = *(int **)(&DAT_008376c8 + (param_1 - 1U >> 3) * 4);

  if (piVar1 != (int *)0x0) {

    *(int *)(&DAT_008376c8 + (param_1 - 1U >> 3) * 4) = *piVar1;

    _DAT_008376c0 = 0;

    return;

  }

  FUN_00404e80(param_1);

  _DAT_008376c0 = 0;

  return;

}





// --- FUN_00405120 at 0x00405120 (size: 153) ---


uint __thiscall FUN_00405120(int param_1,int *param_2)



{

  int *piVar1;

  uint in_EAX;

  LONG LVar2;

  int iVar3;

  undefined4 *puVar4;

  

  piVar1 = *(int **)(param_1 + 4);

  if (piVar1 == (int *)0x0) {

    return in_EAX & 0xffffff00;

  }

  iVar3 = piVar1[1];

  *(int *)(param_1 + 4) = iVar3;

  if (iVar3 == 0) {

    *(undefined4 *)(param_1 + 8) = 0;

  }

  else {

    *(undefined4 *)(iVar3 + 8) = 0;

  }

  iVar3 = *param_2;

  if (iVar3 != *piVar1) {

    LVar2 = InterlockedDecrement((LONG *)(iVar3 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar3 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar3 + -0x14))(1);

    }

    iVar3 = *piVar1;

    *param_2 = iVar3;

    InterlockedIncrement((LONG *)(iVar3 + -0x10));

  }

  puVar4 = (undefined4 *)(*piVar1 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(*piVar1 + -0x10));

  if ((LVar2 == 0) && (puVar4 != (undefined4 *)0x0)) {

    (**(code **)*puVar4)(1);

  }

  operator_delete(piVar1);

  iVar3 = *(int *)(param_1 + 0xc) + -1;

  *(int *)(param_1 + 0xc) = iVar3;

  return CONCAT31((int3)((uint)iVar3 >> 8),1);

}





// --- FUN_004051c0 at 0x004051C0 (size: 74) ---


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



void FUN_004051c0(undefined4 *param_1,uint param_2)



{

  if (0x80 < param_2) {

    operator_delete(param_1);

    return;

  }

  FUN_00404d90(&DAT_008376c0);

  *param_1 = *(undefined4 *)(&DAT_008376c8 + (param_2 - 1 >> 3) * 4);

  *(undefined4 **)(&DAT_008376c8 + (param_2 - 1 >> 3) * 4) = param_1;

  _DAT_008376c0 = 0;

  return;

}





// --- FUN_00405210 at 0x00405210 (size: 90) ---


void __fastcall FUN_00405210(int param_1)



{

  LONG LVar1;

  undefined4 *puVar2;

  undefined *local_4;

  

  while (*(int *)(param_1 + 4) != 0) {

    local_4 = PTR_DAT_00818344;

    InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

    FUN_00405120(&local_4);

    puVar2 = (undefined4 *)(local_4 + -0x14);

    LVar1 = InterlockedDecrement((LONG *)(local_4 + -0x10));

    if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

      (**(code **)*puVar2)(1);

    }

  }

  return;

}





// --- FUN_00405270 at 0x00405270 (size: 36) ---


undefined4 * __thiscall FUN_00405270(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_00795074;

  FUN_00405210();

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_004052a0 at 0x004052A0 (size: 247) ---


void __thiscall

FUN_004052a0(int *param_1,void *param_2,undefined4 *param_3,undefined4 param_4,undefined4 *param_5,

            char param_6)



{

  int iVar1;

  void *pvVar2;

  void *pvVar3;

  uint *puVar4;

  uint uVar5;

  size_t _Size;

  undefined4 *_Dst;

  uint local_4;

  

  uVar5 = (uint)param_5;

  local_4 = param_1[1] - *param_1 >> 2;

  puVar4 = (uint *)&param_5;

  if (param_5 <= local_4) {

    puVar4 = &local_4;

  }

  local_4 = *puVar4 + local_4;

  if (local_4 == 0) {

    param_5 = (undefined4 *)0x0;

  }

  else if (local_4 * 4 < 0x81) {

    param_5 = (undefined4 *)FUN_004050d0(local_4 * 4);

  }

  else {

    param_5 = (undefined4 *)FUN_005df0f5();

  }

  pvVar3 = (void *)*param_1;

  _Dst = param_5;

  if (param_2 != pvVar3) {

    pvVar2 = memmove(param_5,pvVar3,(int)param_2 - (int)pvVar3);

    _Dst = (undefined4 *)((int)pvVar2 + ((int)param_2 - (int)pvVar3));

  }

  for (; uVar5 != 0; uVar5 = uVar5 - 1) {

    *_Dst = *param_3;

    _Dst = _Dst + 1;

  }

  if ((param_6 == '\0') && ((void *)param_1[1] != param_2)) {

    _Size = param_1[1] - (int)param_2;

    pvVar3 = memmove(_Dst,param_2,_Size);

    _Dst = (undefined4 *)((int)pvVar3 + _Size);

  }

  iVar1 = *param_1;

  if (iVar1 != 0) {

    FUN_004051c0(iVar1,(param_1[2] - iVar1 >> 2) << 2);

  }

  param_1[1] = (int)_Dst;

  *param_1 = (int)param_5;

  param_1[2] = (int)(param_5 + local_4);

  return;

}





// --- FUN_004053a0 at 0x004053A0 (size: 433) ---


uint __thiscall FUN_004053a0(undefined4 *param_1,int *param_2,int *param_3)



{

  char cVar1;

  char *pcVar2;

  char *pcVar3;

  LONG LVar4;

  char *_Source;

  char *pcVar5;

  size_t _Count;

  int *piVar6;

  int iVar7;

  char *local_18;

  char *local_14;

  char *local_10;

  int local_c;

  int *local_8;

  int *local_4;

  

  piVar6 = (int *)0x0;

  local_c = 0;

  local_8 = (int *)0x0;

  local_4 = (int *)0x0;

  for (pcVar2 = strstr((char *)*param_1,(char *)*param_2); pcVar2 != (char *)0x0;

      pcVar2 = strstr(pcVar2 + *(int *)((char *)*param_2 + -4) + -1,(char *)*param_2)) {

    local_14 = pcVar2;

    if (piVar6 == local_4) {

      FUN_004052a0(piVar6,&local_14,&param_3,1,1);

    }

    else {

      if (piVar6 != (int *)0x0) {

        *piVar6 = (int)pcVar2;

      }

      local_8 = piVar6 + 1;

    }

    piVar6 = local_8;

  }

  local_14 = (char *)((int)piVar6 - local_c >> 2);

  if (local_14 == (char *)0x0) {

    if (local_c != 0) {

      FUN_004051c0(local_c,((int)local_4 - local_c >> 2) << 2);

    }

    return 0;

  }

  _Source = (char *)*param_1;

  local_10 = _Source + -0x14;

  FUN_00401280((*(int *)(*param_3 + -4) - *(int *)(*param_2 + -4)) * (int)local_14 + -1 +

               *(int *)(_Source + -4));

  pcVar2 = (char *)*param_1;

  local_18 = (char *)0x0;

  pcVar3 = _Source + -0x14;

  if (local_14 != (char *)0x0) {

    do {

      _Count = *(int *)(local_c + (int)local_18 * 4) - (int)_Source;

      strncpy(pcVar2,_Source,_Count);

      pcVar3 = (char *)*param_3;

      pcVar5 = pcVar2 + _Count;

      do {

        cVar1 = *pcVar3;

        pcVar3 = pcVar3 + 1;

        *pcVar5 = cVar1;

        pcVar5 = pcVar5 + 1;

      } while (cVar1 != '\0');

      pcVar2 = pcVar2 + _Count + *(int *)(*param_3 + -4) + -1;

      _Source = _Source + *(int *)(*param_2 + -4) + _Count + -1;

      local_18 = local_18 + 1;

      pcVar3 = local_10;

    } while (local_18 < local_14);

  }

  iVar7 = (int)pcVar2 - (int)_Source;

  do {

    cVar1 = *_Source;

    _Source[iVar7] = cVar1;

    _Source = _Source + 1;

  } while (cVar1 != '\0');

  LVar4 = InterlockedDecrement((LONG *)(pcVar3 + 4));

  if ((LVar4 == 0) && (pcVar3 != (char *)0x0)) {

    (*(code *)**(undefined4 **)pcVar3)(1);

  }

  if (local_c != 0) {

    FUN_004051c0(local_c,((int)local_4 - local_c >> 2) << 2);

  }

  return (uint)local_14;

}





// --- FUN_00405560 at 0x00405560 (size: 37) ---


void FUN_00405560(void)



{

  FUN_00405a60("kernel32.dll","MultiByteToWideChar",&PTR_FUN_00837394,DAT_009067c4,

               _GodotFailMultiByteToWideChar_24);

                    /* WARNING: Could not recover jumptable at 0x0040557f. Too many branches */

                    /* WARNING: Treating indirect jump as call */

  (*(code *)PTR_FUN_00837394)();

  return;

}





// --- FUN_00405585 at 0x00405585 (size: 125) ---


undefined2 FUN_00405585(byte *param_1,int param_2,int param_3,int param_4,int param_5)



{

  byte bVar1;

  byte *pbVar2;

  int iVar3;

  int iVar4;

  byte *pbVar5;

  bool bVar6;

  int local_8;

  

  local_8 = 0;

  param_2 = param_2 + -1;

  if (-1 < param_2) {

    do {

      iVar4 = param_2 + local_8 >> 1;

      pbVar2 = (byte *)(*(int *)(param_4 + iVar4 * 4) + param_3);

      pbVar5 = param_1;

      do {

        bVar1 = *pbVar5;

        bVar6 = bVar1 < *pbVar2;

        if (bVar1 != *pbVar2) {

LAB_004055ce:

          iVar3 = (1 - (uint)bVar6) - (uint)(bVar6 != 0);

          goto LAB_004055d3;

        }

        if (bVar1 == 0) break;

        bVar1 = pbVar5[1];

        bVar6 = bVar1 < pbVar2[1];

        if (bVar1 != pbVar2[1]) goto LAB_004055ce;

        pbVar5 = pbVar5 + 2;

        pbVar2 = pbVar2 + 2;

      } while (bVar1 != 0);

      iVar3 = 0;

LAB_004055d3:

      if (iVar3 < 0) {

        param_2 = iVar4 + -1;

      }

      else {

        if (iVar3 < 1) break;

        local_8 = iVar4 + 1;

      }

    } while (local_8 <= param_2);

    if (local_8 <= param_2) {

      return *(undefined2 *)(param_5 + iVar4 * 2);

    }

  }

  return 0xffff;

}





// --- FUN_00405602 at 0x00405602 (size: 58) ---


int FUN_00405602(int param_1,ushort param_2,undefined4 *param_3)



{

  int iVar1;

  int iVar2;

  uint uVar3;

  

  iVar1 = *(int *)(param_1 + 0x3c) + param_1;

  if (((iVar1 == 0) || (uVar3 = (uint)param_2, *(uint *)(iVar1 + 0x74) <= uVar3)) ||

     (iVar2 = *(int *)(iVar1 + 0x78 + uVar3 * 8), iVar2 == 0)) {

    *param_3 = 0;

    iVar2 = 0;

  }

  else {

    *param_3 = *(undefined4 *)(iVar1 + 0x7c + uVar3 * 8);

    iVar2 = iVar2 + param_1;

  }

  return iVar2;

}





// --- FUN_0040563c at 0x0040563C (size: 35) ---


bool FUN_0040563c(PCNZCH param_1,PCNZCH param_2)



{

  int iVar1;

  

  iVar1 = CompareStringA(0x409,1,param_1,-1,param_2,-1);

  return iVar1 == 2;

}





// --- FUN_0040565f at 0x0040565F (size: 63) ---


char * FUN_0040565f(char *param_1,char *param_2,int param_3)



{

  char cVar1;

  uint uVar2;

  uint uVar3;

  char *pcVar4;

  

  pcVar4 = param_1;

  if (param_3 != 0) {

    do {

      cVar1 = *param_2;

      *pcVar4 = cVar1;

      pcVar4 = pcVar4 + 1;

      param_2 = param_2 + 1;

      if (cVar1 == '\0') break;

      param_3 = param_3 + -1;

    } while (param_3 != 0);

    if ((param_3 != 0) && (uVar2 = param_3 - 1, uVar2 != 0)) {

      for (uVar3 = uVar2 >> 2; uVar3 != 0; uVar3 = uVar3 - 1) {

        pcVar4[0] = '\0';

        pcVar4[1] = '\0';

        pcVar4[2] = '\0';

        pcVar4[3] = '\0';

        pcVar4 = pcVar4 + 4;

      }

      for (uVar2 = uVar2 & 3; uVar2 != 0; uVar2 = uVar2 - 1) {

        *pcVar4 = '\0';

        pcVar4 = pcVar4 + 1;

      }

    }

  }

  return param_1;

}





// --- _GetProcAddressInternal@8 at 0x0040569E (size: 100) ---


/* Library Function - Single Match

    _GetProcAddressInternal@8

   

   Libraries: Visual Studio 2005 Release, Visual Studio 2008 Release, Visual Studio 2010 Release,

   Visual Studio 2015 Release */



uint _GetProcAddressInternal_8(int param_1,int param_2)



{

  int iVar1;

  uint uVar2;

  uint uVar3;

  

  iVar1 = param_1;

  if (((param_1 != 0) && (param_2 != 0)) && (uVar2 = FUN_00405602(param_1,0,&param_1), uVar2 != 0))

  {

    uVar3 = FUN_00405585(param_2,*(undefined4 *)(uVar2 + 0x18),iVar1,*(int *)(uVar2 + 0x20) + iVar1,

                         *(int *)(uVar2 + 0x24) + iVar1);

    if ((uVar3 & 0xffff) < *(uint *)(uVar2 + 0x14)) {

      uVar3 = *(int *)(*(int *)(uVar2 + 0x1c) + (uVar3 & 0xffff) * 4 + iVar1) + iVar1;

      if (uVar3 <= uVar2) {

        return uVar3;

      }

      if (param_1 + uVar2 <= uVar3) {

        return uVar3;

      }

    }

  }

  return 0;

}





// --- FUN_00405702 at 0x00405702 (size: 155) ---


void FUN_00405702(char *param_1,undefined1 *param_2,undefined1 *param_3)



{

  char *pcVar1;

  uint uVar2;

  char cVar3;

  char *pcVar4;

  

  pcVar1 = param_1;

  do {

    cVar3 = *pcVar1;

    pcVar1 = pcVar1 + 1;

  } while (cVar3 != '\0');

  if ((pcVar1 == param_1 + 1) || (param_1[1] != ':')) {

    if (param_2 != (undefined1 *)0x0) {

      *param_2 = 0;

    }

  }

  else {

    if (param_2 != (undefined1 *)0x0) {

      FUN_0040565f(param_2,param_1,2);

      param_2[2] = 0;

    }

    param_1 = param_1 + 2;

  }

  cVar3 = *param_1;

  pcVar1 = (char *)0x0;

  pcVar4 = param_1;

  if (cVar3 != '\0') {

    do {

      if ((cVar3 == '/') || (cVar3 == '\\')) {

        pcVar1 = pcVar4 + 1;

      }

      pcVar4 = pcVar4 + 1;

      cVar3 = *pcVar4;

    } while (cVar3 != '\0');

    if (pcVar1 != (char *)0x0) {

      if (param_3 == (undefined1 *)0x0) {

        return;

      }

      uVar2 = (int)pcVar1 - (int)param_1;

      if (0xff < uVar2) {

        uVar2 = 0xff;

      }

      FUN_0040565f(param_3,param_1,uVar2);

      param_3[uVar2] = 0;

      return;

    }

  }

  if (param_3 != (undefined1 *)0x0) {

    *param_3 = 0;

  }

  return;

}





// --- FUN_0040579d at 0x0040579D (size: 707) ---


/* WARNING: Type propagation algorithm not settling */



HMODULE FUN_0040579d(void)



{

  char cVar1;

  HKEY *ppHVar2;

  UINT UVar3;

  DWORD DVar4;

  HMODULE pHVar5;

  char *pcVar6;

  HKEY *ppHVar7;

  int iVar8;

  LONG LVar9;

  code *pcVar10;

  code *pcVar11;

  char *pcVar12;

  uint uVar13;

  uint uVar14;

  char *pcVar15;

  CHAR local_530 [264];

  CHAR local_428 [264];

  char local_320 [256];

  CHAR local_220 [263];

  char acStack_119 [265];

  undefined4 local_10;

  HMODULE local_c;

  HKEY local_8;

  

  if ((DAT_009067c0 == (code *)0x0) ||

     (local_c = (HMODULE)(*DAT_009067c0)(), local_c == (HMODULE)0x0)) {

    local_c = LoadLibraryA(PTR_s_unicows_dll_008182a0);

    if (local_c != (HMODULE)0x0) {

      UVar3 = GetSystemDirectoryA(local_530,0x104);

      if (UVar3 == 0) {

        local_530[0] = '\0';

      }

      UVar3 = GetWindowsDirectoryA(local_428,0x104);

      if (UVar3 == 0) {

        local_428[0] = '\0';

      }

      DVar4 = GetModuleFileNameA(local_c,local_220,0x104);

      if (DVar4 == 0) {

        local_220[0] = '\0';

      }

      DVar4 = 0x104;

      pcVar6 = acStack_119 + 1;

      pHVar5 = GetModuleHandleA((LPCSTR)0x0);

      DVar4 = GetModuleFileNameA(pHVar5,pcVar6,DVar4);

      if (DVar4 == 0) {

        acStack_119[1] = 0;

      }

      FUN_00405702(acStack_119 + 1,&local_8,local_320);

      ppHVar2 = &local_8;

      do {

        ppHVar7 = ppHVar2;

        ppHVar2 = (HKEY *)((int)ppHVar7 + 1);

      } while (*(char *)ppHVar7 != '\0');

      pcVar6 = local_320;

      do {

        cVar1 = *pcVar6;

        pcVar6 = pcVar6 + 1;

      } while (cVar1 != '\0');

      (pcVar6 + (int)(ppHVar7 + 0x84))[-(int)&stack0x00000000] = '\0';

      FUN_00405702(local_220,&local_8,local_320);

      ppHVar2 = &local_8;

      do {

        ppHVar7 = ppHVar2;

        ppHVar2 = (HKEY *)((int)ppHVar7 + 1);

      } while (*(char *)ppHVar7 != '\0');

      pcVar6 = local_320;

      do {

        cVar1 = *pcVar6;

        pcVar6 = pcVar6 + 1;

      } while (cVar1 != '\0');

      (pcVar6 + (int)(ppHVar7 + 0x42))[-(int)&stack0x00000000] = '\0';

      iVar8 = FUN_0040563c(local_428,local_220);

      if (((iVar8 == 0) && (iVar8 = FUN_0040563c(local_428,acStack_119 + 1), iVar8 != 0)) ||

         ((iVar8 = FUN_0040563c(local_530,local_220), iVar8 == 0 &&

          (iVar8 = FUN_0040563c(local_530,acStack_119 + 1), iVar8 != 0)))) {

        FreeLibrary(local_c);

        local_c = (HMODULE)0x0;

      }

      if (local_c != (HMODULE)0x0) {

        return local_c;

      }

    }

    local_8 = (HKEY)0x0;

    pHVar5 = LoadLibraryA("advapi32.dll");

    LVar9 = InterlockedExchange(&DAT_008182c4,(LONG)pHVar5);

    if (LVar9 != 0) {

      FreeLibrary(pHVar5);

    }

    if (DAT_008182c4 != 0) {

      pcVar10 = (code *)_GetProcAddressInternal_8(DAT_008182c4,"RegOpenKeyExA");

      pcVar11 = (code *)_GetProcAddressInternal_8(DAT_008182c4,"RegQueryValueExA");

      if (((pcVar10 != (code *)0x0) && (pcVar11 != (code *)0x0)) &&

         (iVar8 = (*pcVar10)(0x80000002,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",0,1,&local_8)

         , iVar8 == 0)) {

        local_10 = 0x104;

        acStack_119[1] = 0;

        iVar8 = (*pcVar11)(local_8,"CommonFilesDir",0,0,acStack_119 + 1,&local_10);

        if (iVar8 == 0) {

          pcVar6 = "\\Microsoft Shared\\MSLU\\";

          do {

            pcVar12 = pcVar6;

            pcVar6 = pcVar12 + 1;

          } while (*pcVar12 != '\0');

          pcVar6 = acStack_119;

          do {

            pcVar15 = pcVar6 + 1;

            pcVar6 = pcVar6 + 1;

          } while (*pcVar15 != '\0');

          pcVar15 = "\\Microsoft Shared\\MSLU\\";

          for (uVar13 = (uint)(pcVar12 + -0x7951df) >> 2; uVar13 != 0; uVar13 = uVar13 - 1) {

            *(undefined4 *)pcVar6 = *(undefined4 *)pcVar15;

            pcVar15 = pcVar15 + 4;

            pcVar6 = pcVar6 + 4;

          }

          for (uVar13 = (uint)(pcVar12 + -0x7951df) & 3; pcVar12 = PTR_s_unicows_dll_008182a0,

              uVar13 != 0; uVar13 = uVar13 - 1) {

            *pcVar6 = *pcVar15;

            pcVar15 = pcVar15 + 1;

            pcVar6 = pcVar6 + 1;

          }

          do {

            cVar1 = *pcVar12;

            pcVar12 = pcVar12 + 1;

          } while (cVar1 != '\0');

          uVar13 = (int)pcVar12 - (int)PTR_s_unicows_dll_008182a0;

          pcVar6 = acStack_119;

          do {

            pcVar12 = pcVar6 + 1;

            pcVar6 = pcVar6 + 1;

          } while (*pcVar12 != '\0');

          pcVar12 = PTR_s_unicows_dll_008182a0;

          for (uVar14 = uVar13 >> 2; uVar14 != 0; uVar14 = uVar14 - 1) {

            *(undefined4 *)pcVar6 = *(undefined4 *)pcVar12;

            pcVar12 = pcVar12 + 4;

            pcVar6 = pcVar6 + 4;

          }

          for (uVar13 = uVar13 & 3; uVar13 != 0; uVar13 = uVar13 - 1) {

            *pcVar6 = *pcVar12;

            pcVar12 = pcVar12 + 1;

            pcVar6 = pcVar6 + 1;

          }

          local_c = LoadLibraryA(acStack_119 + 1);

        }

        RegCloseKey(local_8);

      }

    }

  }

  return local_c;

}





// --- FUN_00405a60 at 0x00405A60 (size: 339) ---


void FUN_00405a60(byte *param_1,undefined4 param_2,LONG *param_3,int param_4,LONG param_5)



{

  LONG *Target;

  byte bVar1;

  DWORD DVar2;

  byte *pbVar3;

  int iVar4;

  HMODULE pHVar5;

  LONG LVar6;

  byte *pbVar7;

  int iVar8;

  bool bVar9;

  _MEMORY_BASIC_INFORMATION local_20;

  

  if (DAT_00837718 == 0) {

    DVar2 = GetVersion();

    if (0x7fffffff < DVar2) {

      DAT_00837718 = 2;

      goto LAB_00405a9b;

    }

    DAT_00837718 = 1;

LAB_00405aaa:

    iVar8 = 1;

    pbVar7 = PTR_s_kernel32_dll_008182a8;

    if (DAT_0083771c == (HANDLE)0x0) {

      VirtualQuery(FUN_00405a60,&local_20,0x1c);

      DAT_0083771c = local_20.AllocationBase;

      pbVar7 = PTR_s_kernel32_dll_008182a8;

    }

    while (pbVar3 = param_1, pbVar7 != (byte *)0x0) {

      do {

        bVar1 = *pbVar3;

        bVar9 = bVar1 < *pbVar7;

        if (bVar1 != *pbVar7) {

LAB_00405afb:

          iVar4 = (1 - (uint)bVar9) - (uint)(bVar9 != 0);

          goto LAB_00405b00;

        }

        if (bVar1 == 0) break;

        bVar1 = pbVar3[1];

        bVar9 = bVar1 < pbVar7[1];

        if (bVar1 != pbVar7[1]) goto LAB_00405afb;

        pbVar7 = pbVar7 + 2;

        pbVar3 = pbVar3 + 2;

      } while (bVar1 != 0);

      iVar4 = 0;

LAB_00405b00:

      if (iVar4 == 0) {

        Target = &DAT_008182a4 + iVar8 * 2;

        if (*Target == 0) {

          pHVar5 = LoadLibraryA((LPCSTR)param_1);

          LVar6 = InterlockedExchange(Target,(LONG)pHVar5);

          if (LVar6 != 0) {

            FreeLibrary(pHVar5);

          }

        }

        LVar6 = *Target;

        goto LAB_00405ba0;

      }

      iVar4 = iVar8 * 2;

      iVar8 = iVar8 + 1;

      pbVar7 = (&PTR_s_kernel32_dll_008182a8)[iVar4];

    }

  }

  else {

LAB_00405a9b:

    if (DAT_00837718 == 1) goto LAB_00405aaa;

    if (param_4 == 0) {

      LVar6 = DAT_008182a4;

      if (DAT_008182a4 != 0) {

LAB_00405ba0:

        param_4 = _GetProcAddressInternal_8(LVar6,param_2);

        goto LAB_00405ba5;

      }

      pHVar5 = (HMODULE)FUN_0040579d();

      if ((pHVar5 != (HMODULE)0x0) &&

         (LVar6 = InterlockedExchange(&DAT_008182a4,(LONG)pHVar5), LVar6 != 0)) {

        FreeLibrary(pHVar5);

      }

      LVar6 = DAT_008182a4;

      if (DAT_008182a4 != 0) goto LAB_00405ba0;

    }

    else {

LAB_00405ba5:

      if (param_4 != 0) goto LAB_00405b13;

    }

  }

  param_4 = param_5;

LAB_00405b13:

  InterlockedExchange(param_3,param_4);

  FlushInstructionCache(DAT_0083771c,param_3,4);

  return;

}





// --- _GodotFailMultiByteToWideChar@24 at 0x00405C68 (size: 46) ---


/* Library Function - Single Match

    _GodotFailMultiByteToWideChar@24

   

   Libraries: Visual Studio 2005 Release, Visual Studio 2008 Release, Visual Studio 2010 Release,

   Visual Studio 2015 Release */



undefined4 _GodotFailMultiByteToWideChar_24(void)



{

  HMODULE pHVar1;

  code *UNRECOVERED_JUMPTABLE;

  undefined4 uVar2;

  char *pcVar3;

  

  pcVar3 = "MultiByteToWideChar";

  pHVar1 = GetModuleHandleA("kernel32.dll");

  UNRECOVERED_JUMPTABLE = (code *)_GetProcAddressInternal_8(pHVar1,pcVar3);

  if (UNRECOVERED_JUMPTABLE != (code *)0x0) {

                    /* WARNING: Could not recover jumptable at 0x00405c86. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    uVar2 = (*UNRECOVERED_JUMPTABLE)();

    return uVar2;

  }

  SetLastError(0x7f);

  return 0;

}





// --- FID_conflict:_GodotFailWideCharToMultiByte@32 at 0x00405C96 (size: 46) ---


/* Library Function - Multiple Matches With Different Base Names

    _GodotFailExtTextOutW@32

    _GodotFailWideCharToMultiByte@32

   

   Libraries: Visual Studio 2005 Release, Visual Studio 2008 Release, Visual Studio 2010 Release,

   Visual Studio 2015 Release */



undefined4 FID_conflict__GodotFailWideCharToMultiByte_32(void)



{

  HMODULE pHVar1;

  code *UNRECOVERED_JUMPTABLE;

  undefined4 uVar2;

  char *pcVar3;

  

  pcVar3 = "WideCharToMultiByte";

  pHVar1 = GetModuleHandleA("kernel32.dll");

  UNRECOVERED_JUMPTABLE = (code *)_GetProcAddressInternal_8(pHVar1,pcVar3);

  if (UNRECOVERED_JUMPTABLE != (code *)0x0) {

                    /* WARNING: Could not recover jumptable at 0x00405cb4. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    uVar2 = (*UNRECOVERED_JUMPTABLE)();

    return uVar2;

  }

  SetLastError(0x7f);

  return 0;

}





// --- FID_conflict:_GodotFailWideCharToMultiByte@32 at 0x00405D81 (size: 46) ---


/* Library Function - Multiple Matches With Different Base Names

    _GodotFailExtTextOutW@32

    _GodotFailWideCharToMultiByte@32

   

   Libraries: Visual Studio 2005 Release, Visual Studio 2008 Release, Visual Studio 2010 Release,

   Visual Studio 2015 Release */



undefined4 FID_conflict__GodotFailWideCharToMultiByte_32(void)



{

  HMODULE pHVar1;

  code *UNRECOVERED_JUMPTABLE;

  undefined4 uVar2;

  char *pcVar3;

  

  pcVar3 = "ExtTextOutW";

  pHVar1 = GetModuleHandleA("gdi32.dll");

  UNRECOVERED_JUMPTABLE = (code *)_GetProcAddressInternal_8(pHVar1,pcVar3);

  if (UNRECOVERED_JUMPTABLE != (code *)0x0) {

                    /* WARNING: Could not recover jumptable at 0x00405d9f. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    uVar2 = (*UNRECOVERED_JUMPTABLE)();

    return uVar2;

  }

  SetLastError(0x7f);

  return 0;

}





// --- FUN_00405de0 at 0x00405DE0 (size: 119) ---


undefined4 FUN_00405de0(LPTHREAD_START_ROUTINE param_1,undefined4 *param_2)



{

  HANDLE pvVar1;

  DWORD DVar2;

  

  pvVar1 = CreateEventA((LPSECURITY_ATTRIBUTES)0x0,1,0,(LPCSTR)0x0);

  *param_2 = pvVar1;

  pvVar1 = CreateThread((LPSECURITY_ATTRIBUTES)0x0,0,param_1,param_2,0,param_2 + 1);

  if (pvVar1 != (HANDLE)0x0) {

    DVar2 = WaitForSingleObject((HANDLE)*param_2,1000);

    if (DVar2 == 0) {

      WaitForSingleObject(pvVar1,0xffffffff);

      CloseHandle(pvVar1);

      CloseHandle((HANDLE)*param_2);

      return 1;

    }

    CloseHandle(pvVar1);

  }

  CloseHandle((HANDLE)*param_2);

  return 0;

}





// --- FUN_00405e60 at 0x00405E60 (size: 31) ---


void FUN_00405e60(uint param_1,char param_2)



{

  if (param_2 != '\0') {

    DAT_00818338 = DAT_00818338 | param_1;

    return;

  }

  DAT_00818338 = DAT_00818338 & ~param_1;

  return;

}





// --- FUN_00405e80 at 0x00405E80 (size: 6) ---


undefined4 FUN_00405e80(void)



{

  return DAT_00818338;

}





// --- FUN_00405e90 at 0x00405E90 (size: 22) ---


bool FUN_00405e90(uint param_1)



{

  return (DAT_00818338 & param_1) == param_1;

}





// --- FUN_00405eb0 at 0x00405EB0 (size: 30) ---


void FUN_00405eb0(void)



{

  if (DAT_00837724 == '\0') {

    FUN_0040e3a0();

    DAT_00837724 = '\x01';

                    /* WARNING: Subroutine does not return */

    _exit(0);

  }

  return;

}





// --- FUN_00405ed0 at 0x00405ED0 (size: 84) ---


undefined4 FUN_00405ed0(undefined4 param_1)



{

  uint uVar1;

  undefined4 uVar2;

  uint uVar3;

  

  uVar3 = DAT_00818338 & 0x4000;

  DAT_00818338 = DAT_00818338 & 0xffffbfff;

  FUN_0040e3a0();

  uVar1 = DAT_00818338;

  DAT_00818338 = DAT_00818338 & 0xffffffb7;

  if (uVar3 == 0x4000) {

    DAT_00818338 = DAT_00818338 | 0x4000;

  }

  else {

    DAT_00818338 = uVar1 & 0xffffbfb7;

  }

  if (DAT_00837728 != (code *)0x0) {

    uVar2 = (*DAT_00837728)(param_1);

    return uVar2;

  }

  return 0;

}





// --- FUN_00405f30 at 0x00405F30 (size: 9) ---


void __fastcall FUN_00405f30(undefined4 *param_1)



{

  *param_1 = &PTR_LAB_007952b0;

  return;

}





// --- FUN_00405f40 at 0x00405F40 (size: 37) ---


void __fastcall FUN_00405f40(undefined4 *param_1)



{

  *param_1 = &PTR_LAB_007952b0;

  if (DAT_00837728 != (LPTOP_LEVEL_EXCEPTION_FILTER)0x0) {

    SetUnhandledExceptionFilter(DAT_00837728);

    DAT_00837728 = (LPTOP_LEVEL_EXCEPTION_FILTER)0x0;

  }

  FUN_0040e880();

  return;

}





// --- FUN_00405f70 at 0x00405F70 (size: 40) ---


LONG __fastcall FUN_00405f70(undefined4 *param_1)



{

  LONG LVar1;

  

  LVar1 = InterlockedDecrement(param_1 + 1);

  if (LVar1 != 0) {

    return param_1[1];

  }

  if (param_1 != (undefined4 *)0x0) {

    (**(code **)*param_1)(1);

  }

  return 0;

}





// --- FUN_00405fa0 at 0x00405FA0 (size: 72) ---


void FUN_00405fa0(char param_1,uint param_2)



{

  uint uVar1;

  

  uVar1 = _control87(0,0);

  _clearfp();

  if (param_1 == '\0') {

    _control87(uVar1 | param_2,0x8001f);

    return;

  }

  _control87(uVar1 & ~param_2,0x8001f);

  return;

}





// --- FUN_00405ff0 at 0x00405FF0 (size: 39) ---


undefined4 FUN_00405ff0(undefined4 *param_1)



{

  undefined4 uVar1;

  

  SetEvent((HANDLE)*param_1);

  uVar1 = FUN_00405ed0(param_1[2],param_1 + 4);

  param_1[3] = uVar1;

  return 0;

}





// --- FUN_00406020 at 0x00406020 (size: 119) ---


undefined4 FUN_00406020(undefined4 param_1)



{

  char cVar1;

  undefined4 uVar2;

  undefined1 local_20 [8];

  undefined4 local_18;

  undefined4 local_14;

  

  DAT_0081833c = 0;

  local_18 = param_1;

  FUN_0040e7d0(param_1);

  cVar1 = FUN_00405de0(FUN_00405ff0,local_20);

  if (cVar1 != '\0') {

    FUN_0040e7b0();

    return local_14;

  }

  if (DAT_00837728 != (code *)0x0) {

    uVar2 = (*DAT_00837728)(param_1);

    FUN_0040e7b0();

    return uVar2;

  }

  FUN_0040e7b0();

  return 0;

}





// --- FUN_004060a0 at 0x004060A0 (size: 374) ---


undefined4 FUN_004060a0(undefined4 *param_1)



{

  int iVar1;

  undefined4 uVar2;

  HANDLE pvVar3;

  LPVOID pvVar4;

  bool bVar5;

  DWORD DVar6;

  SIZE_T SVar7;

  undefined1 local_10 [16];

  

  _clearfp();

  iVar1 = *(int *)*param_1;

  if (iVar1 == -0x7ffffffd) {

LAB_004060e1:

    if (DAT_00837728 != (code *)0x0) {

      uVar2 = (*DAT_00837728)(param_1);

      return uVar2;

    }

    return 0;

  }

  if ((iVar1 == -0x3fffffe9) && ((DAT_00818338._1_1_ & 0x40) == 0)) {

    return 0xffffffff;

  }

  if (DAT_0083773c != '\0') {

    FUN_0040e3a0();

    goto LAB_004060e1;

  }

  DAT_0083773c = '\x01';

  if (iVar1 != -0x3fffffe9) {

    SVar7 = 0x400000;

    DVar6 = 0;

    pvVar3 = GetProcessHeap();

    pvVar4 = HeapAlloc(pvVar3,DVar6,SVar7);

    bVar5 = pvVar4 != (LPVOID)0x0;

    DVar6 = 0;

    pvVar3 = GetProcessHeap();

    HeapFree(pvVar3,DVar6,pvVar4);

    if (bVar5) goto LAB_004061a6;

  }

  if (DAT_00837734 != (LPVOID)0x0) {

    VirtualFree(DAT_00837734,0,0x8000);

  }

  SVar7 = 0x400000;

  DVar6 = 0;

  DAT_00837734 = (LPVOID)0x0;

  pvVar3 = GetProcessHeap();

  pvVar4 = HeapAlloc(pvVar3,DVar6,SVar7);

  bVar5 = pvVar4 == (LPVOID)0x0;

  DVar6 = 0;

  pvVar3 = GetProcessHeap();

  HeapFree(pvVar3,DVar6,pvVar4);

  if (bVar5) {

    FUN_0040e3a0();

    if (DAT_00837728 != (code *)0x0) {

      uVar2 = (*DAT_00837728)(param_1);

      return uVar2;

    }

    return 0;

  }

LAB_004061a6:

  if ((*(int *)*param_1 == -0x3fffff03) && (DAT_0081833c != '\0')) {

    uVar2 = FUN_00406020(param_1);

    DAT_0083773c = '\0';

    return uVar2;

  }

  FUN_0040e7d0(param_1);

  uVar2 = FUN_00405ed0(param_1,local_10);

  DAT_0083773c = '\0';

  FUN_0040e7b0();

  return uVar2;

}





// --- FUN_00406220 at 0x00406220 (size: 84) ---


undefined4 FUN_00406220(void)



{

  uint uVar1;

  

  if (((DAT_00818338._1_1_ & 2) != 0) && (DAT_00837728 == (LPTOP_LEVEL_EXCEPTION_FILTER)0x0)) {

    DAT_00837728 = SetUnhandledExceptionFilter(FUN_004060a0);

  }

  if ((DAT_00818338._1_1_ & 4) != 0) {

    uVar1 = _control87(0,0);

    _clearfp();

    _control87(uVar1 & 0xfffffff7,0x8001f);

  }

  return 1;

}





// --- FUN_004062a0 at 0x004062A0 (size: 91) ---


void __thiscall FUN_004062a0(int *param_1,char *param_2,va_list param_3)



{

  int iVar1;

  size_t _Count;

  char *_Dest;

  

  iVar1 = _vsnprintf((char *)*param_1,0x1000,param_2,param_3);

  if (iVar1 < 0) {

    _Count = _vscprintf(param_2,param_3);

    _Dest = (char *)thunk_FUN_005df0f5(_Count + 1);

    if (_Dest != (char *)0x0) {

      *param_1 = (int)_Dest;

      _vsnprintf(_Dest,_Count,param_2,param_3);

      *(undefined1 *)(_Count + *param_1) = 0;

    }

  }

  return;

}





// --- FUN_00406300 at 0x00406300 (size: 129) ---


undefined4 FUN_00406300(undefined4 param_1,undefined4 param_2,uint param_3)



{

  uint uVar1;

  undefined4 uVar2;

  

  DAT_00818338 = DAT_00818338 & ~param_3;

  FUN_00405000(param_1);

  FUN_00405000(param_2);

  if ((DAT_00818338 & 0x2000) != 0) {

    uVar1 = DAT_00818338 & 0x800;

    DAT_00818338 = DAT_00818338 & 0xffffdfff;

    FUN_0040fa40(CONCAT31((int3)(uVar1 >> 8),uVar1 != 0x800));

    if ((DAT_00818338 & 0x200) != 0) {

      DAT_00837734 = VirtualAlloc((LPVOID)0x0,0x6400000,0x2000,4);

    }

                    /* WARNING: Could not recover jumptable at 0x0040637c. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    uVar2 = (*(code *)**(undefined4 **)PTR_DAT_00818550)();

    return uVar2;

  }

  return 1;

}





// --- FUN_00406390 at 0x00406390 (size: 17) ---


bool FUN_00406390(uint *param_1,uint param_2)



{

  return *param_1 < param_2;

}





// --- FUN_004063b0 at 0x004063B0 (size: 64) ---


undefined4 * __thiscall FUN_004063b0(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_007952dc;

  if ((undefined4 *)param_1[0x18] != param_1 + 1) {

    operator_delete__((undefined4 *)param_1[0x18]);

  }

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_004063f0 at 0x004063F0 (size: 71) ---


void __thiscall FUN_004063f0(int param_1,int *param_2)



{

  int *piVar1;

  

  piVar1 = *(int **)(param_1 + 100);

  while( true ) {

    if (piVar1 == (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

      param_2[1] = 0;

      param_2[2] = 0;

      *param_2 = param_1;

      return;

    }

    if (**(int **)(param_1 + 100) != 0) break;

    piVar1 = *(int **)(param_1 + 100) + 1;

    *(int **)(param_1 + 100) = piVar1;

  }

  piVar1 = *(int **)(param_1 + 100);

  param_2[2] = *piVar1;

  param_2[1] = (int)piVar1;

  *param_2 = param_1;

  return;

}





// --- FUN_00406440 at 0x00406440 (size: 85) ---


void __thiscall FUN_00406440(int param_1,int *param_2,uint *param_3)



{

  undefined4 *puVar1;

  uint *puVar2;

  

  puVar1 = (undefined4 *)(*(int *)(param_1 + 0x60) + (*param_3 % *(uint *)(param_1 + 0x68)) * 4);

  for (puVar2 = (uint *)*puVar1;

      (puVar2 != (uint *)0x0 &&

      ((((*puVar2 != *param_3 || (puVar2[1] != param_3[1])) || (puVar2[2] != param_3[2])) ||

       (puVar2[3] != param_3[3])))); puVar2 = (uint *)puVar2[4]) {

  }

  param_2[1] = (int)puVar1;

  *param_2 = param_1;

  param_2[2] = (int)puVar2;

  return;

}





// --- FUN_004064a0 at 0x004064A0 (size: 63) ---


void FUN_004064a0(int param_1,int param_2,uint *param_3)



{

  int iVar1;

  int iVar2;

  

  iVar2 = param_2 - param_1 >> 2;

  if (0 < iVar2) {

    do {

      iVar1 = iVar2 >> 1;

      if (*(uint *)(param_1 + iVar1 * 4) < *param_3) {

        param_1 = param_1 + 4 + iVar1 * 4;

        iVar1 = iVar2 + (-1 - iVar1);

      }

      iVar2 = iVar1;

    } while (0 < iVar1);

  }

  return;

}





// --- FUN_004064e0 at 0x004064E0 (size: 27) ---


void FUN_004064e0(int *param_1)



{

  int iVar1;

  

  iVar1 = *(int *)(*param_1 + -4);

  if (iVar1 != 1) {

    FUN_00404ef0(*param_1,iVar1 + -1);

  }

  return;

}





// --- FUN_00406500 at 0x00406500 (size: 104) ---


undefined4 FUN_00406500(undefined4 param_1,undefined4 param_2)



{

  undefined *puVar1;

  undefined4 uVar2;

  LONG LVar3;

  

  puVar1 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  uVar2 = FUN_00402390(param_2,&stack0x0000000c);

  if (*(int *)(puVar1 + -4) != 1) {

    FUN_00404ef0(puVar1,*(int *)(puVar1 + -4) + -1);

  }

  LVar3 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

  if ((LVar3 == 0) && ((undefined4 *)(puVar1 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(puVar1 + -0x14))(1);

  }

  return uVar2;

}





// --- FUN_00406570 at 0x00406570 (size: 89) ---


void FUN_00406570(undefined4 *param_1,undefined4 param_2,int *param_3)



{

  undefined1 local_c [8];

  int local_4;

  

  *param_3 = 0;

  FUN_00406440(local_c,param_2);

  if (local_4 != 0) {

    *param_3 = *(int *)(local_4 + 0x14);

  }

  if ((int *)*param_3 != (int *)0x0) {

    (**(code **)(*(int *)*param_3 + 0x10))();

    *param_1 = 0;

    return;

  }

  *param_1 = 0x80040154;

  return;

}





// --- FUN_004065d0 at 0x004065D0 (size: 127) ---


void FUN_004065d0(int *param_1,undefined4 param_2,undefined4 param_3)



{

  int *piVar1;

  undefined1 local_c [4];

  undefined4 *puStack_8;

  int local_4;

  

  FUN_00406440(local_c,param_2);

  if ((local_4 != 0) && (*(int **)(local_4 + 0x14) != (int *)0x0)) {

    param_2 = 0;

    piVar1 = (int *)(**(code **)(**(int **)(local_4 + 0x14) + 0xc))(&param_3,param_3,&param_2);

    if (-1 < *piVar1) {

      *param_1 = local_4;

      *puStack_8 = 0;

      return;

    }

    *puStack_8 = 0x80004002;

    return;

  }

  *param_1 = -0x7ffbfeac;

  return;

}





// --- FUN_00406650 at 0x00406650 (size: 139) ---


void FUN_00406650(int *param_1,undefined4 param_2,undefined4 param_3,undefined4 param_4,int *param_5

                 )



{

  int iVar1;

  undefined4 *puVar2;

  int *piVar3;

  int *piVar4;

  undefined4 unaff_EBP;

  int *unaff_ESI;

  int local_4;

  

  puVar2 = param_5;

  *param_5 = 0;

  param_5 = (int *)0x0;

  FUN_004065d0(&local_4,param_2,&DAT_007952cc,&param_5);

  piVar3 = param_5;

  if (local_4 < 0) {

    *param_1 = local_4;

    return;

  }

  param_2 = 0;

  piVar4 = (int *)(**(code **)(*param_5 + 0x18))(&param_5,param_4,param_3,&param_2);

  iVar1 = *piVar4;

  if (-1 < iVar1) {

    *puVar2 = unaff_EBP;

  }

  (**(code **)(*piVar3 + 0x14))();

  *unaff_ESI = iVar1;

  return;

}





// --- FUN_004066e0 at 0x004066E0 (size: 151) ---


undefined4 * __thiscall FUN_004066e0(undefined4 *param_1,uint param_2)



{

  undefined *puVar1;

  uint *puVar2;

  undefined4 uVar3;

  uint uVar4;

  int iVar5;

  undefined4 *puVar6;

  uint local_4;

  

  local_4 = param_2;

  param_2 = param_2 & 0xffffff00;

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  *param_1 = &PTR_FUN_007952dc;

  puVar1 = PTR_DAT_00818558;

  puVar2 = (uint *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,param_2,0);

  if (puVar2 == (uint *)puVar1) {

    puVar2 = puVar2 + -1;

  }

  uVar4 = *puVar2;

  param_1[0x1a] = uVar4;

  if (uVar4 < 0x18) {

    param_1[0x18] = param_1 + 1;

  }

  else {

    uVar3 = thunk_FUN_005df0f5(uVar4 * 4);

    param_1[0x18] = uVar3;

  }

  param_1[0x19] = (undefined4 *)param_1[0x18] + param_1[0x1a];

  puVar6 = (undefined4 *)param_1[0x18];

  for (uVar4 = param_1[0x1a] & 0x3fffffff; uVar4 != 0; uVar4 = uVar4 - 1) {

    *puVar6 = 0;

    puVar6 = puVar6 + 1;

  }

  for (iVar5 = 0; iVar5 != 0; iVar5 = iVar5 + -1) {

    *(undefined1 *)puVar6 = 0;

    puVar6 = (undefined4 *)((int)puVar6 + 1);

  }

  return param_1;

}





// --- FUN_00406780 at 0x00406780 (size: 82) ---


void __fastcall FUN_00406780(int param_1)



{

  undefined *puVar1;

  undefined4 *puVar2;

  uint local_8;

  undefined4 local_4;

  

  puVar1 = PTR_DAT_00818558;

  local_4 = *(undefined4 *)(param_1 + 0x68);

  local_8 = local_8 & 0xffffff00;

  puVar2 = (undefined4 *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,local_8,0);

  if ((puVar2 != (undefined4 *)puVar1) || (puVar2 = puVar2 + -1, puVar2 != (undefined4 *)puVar1)) {

    puVar2 = puVar2 + 1;

  }

  FUN_004067e0(*puVar2);

  return;

}





// --- FUN_004067e0 at 0x004067E0 (size: 234) ---


undefined4 __thiscall FUN_004067e0(int param_1,int param_2)



{

  int iVar1;

  uint *puVar2;

  int *piVar3;

  undefined4 *puVar4;

  uint uVar5;

  uint *puVar6;

  

  if (param_2 == *(int *)(param_1 + 0x68)) {

    return 0;

  }

  iVar1 = *(int *)(param_1 + 0x6c);

  puVar2 = (uint *)0x0;

  do {

    if (iVar1 == 0) {

      if (*(void **)(param_1 + 0x60) != (void *)(param_1 + 4)) {

        operator_delete__(*(void **)(param_1 + 0x60));

      }

      *(undefined4 *)(param_1 + 0x60) = 0;

      *(undefined4 *)(param_1 + 100) = 0;

      *(undefined4 *)(param_1 + 0x68) = 0;

      *(undefined4 *)(param_1 + 0x6c) = 0;

      FUN_0065ec90(param_2);

      while (puVar2 != (uint *)0x0) {

        puVar6 = (uint *)puVar2[4];

        if (*(int *)(param_1 + 0x68) * 2 < *(int *)(param_1 + 0x6c) + 1) {

          FUN_00406780();

        }

        uVar5 = *puVar2 % *(uint *)(param_1 + 0x68);

        iVar1 = *(int *)(param_1 + 0x60);

        puVar2[4] = *(uint *)(iVar1 + uVar5 * 4);

        *(uint **)(iVar1 + uVar5 * 4) = puVar2;

        uVar5 = iVar1 + uVar5 * 4;

        if (uVar5 < *(uint *)(param_1 + 100)) {

          *(uint *)(param_1 + 100) = uVar5;

        }

        *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + 1;

        puVar2 = puVar6;

      }

      return 1;

    }

    piVar3 = *(int **)(param_1 + 100);

    while (piVar3 != (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

      if (**(int **)(param_1 + 100) != 0) {

        puVar4 = *(undefined4 **)(param_1 + 100);

        puVar6 = (uint *)*puVar4;

        goto LAB_0040682e;

      }

      piVar3 = *(int **)(param_1 + 100) + 1;

      *(int **)(param_1 + 100) = piVar3;

    }

    puVar4 = (undefined4 *)0x0;

    puVar6 = (uint *)0x0;

LAB_0040682e:

    FUN_004069d0(param_1,puVar4,puVar6);

    puVar6[4] = (uint)puVar2;

    iVar1 = *(int *)(param_1 + 0x6c);

    puVar2 = puVar6;

  } while( true );

}





// --- FUN_004068d0 at 0x004068D0 (size: 105) ---


uint __thiscall FUN_004068d0(int param_1,uint *param_2)



{

  int iVar1;

  uint uVar2;

  undefined1 local_c [8];

  int local_4;

  

  uVar2 = FUN_00406440(local_c,param_2);

  if (local_4 != 0) {

    return uVar2 & 0xffffff00;

  }

  if (*(int *)(param_1 + 0x68) * 2 < *(int *)(param_1 + 0x6c) + 1) {

    FUN_00406780();

  }

  uVar2 = *param_2 % *(uint *)(param_1 + 0x68);

  iVar1 = *(int *)(param_1 + 0x60);

  param_2[4] = *(uint *)(iVar1 + uVar2 * 4);

  *(uint **)(iVar1 + uVar2 * 4) = param_2;

  uVar2 = iVar1 + uVar2 * 4;

  if (uVar2 < *(uint *)(param_1 + 100)) {

    *(uint *)(param_1 + 100) = uVar2;

  }

  *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + 1;

  return CONCAT31((int3)(uVar2 >> 8),1);

}





// --- FUN_00406940 at 0x00406940 (size: 144) ---


undefined4 FUN_00406940(undefined4 *param_1,undefined4 *param_2)



{

  undefined4 *puVar1;

  undefined1 local_c [8];

  int local_4;

  

  FUN_00406440(local_c,param_1);

  if (local_4 != 0) {

    *(undefined4 *)(local_4 + 0x14) = *param_2;

    return 1;

  }

  puVar1 = (undefined4 *)FUN_005df0f5(0x18);

  if (puVar1 != (undefined4 *)0x0) {

    *puVar1 = *param_1;

    puVar1[1] = param_1[1];

    puVar1[2] = param_1[2];

    puVar1[3] = param_1[3];

    puVar1[4] = 0;

    puVar1[5] = *param_2;

    FUN_004068d0(puVar1);

    return 1;

  }

  FUN_004068d0(0);

  return 1;

}





// --- FUN_004069d0 at 0x004069D0 (size: 58) ---


void __thiscall FUN_004069d0(int param_1,undefined4 param_2,int *param_3,int param_4)



{

  int iVar1;

  int iVar2;

  

  iVar2 = *param_3;

  if (iVar2 != param_4) {

    do {

      iVar1 = iVar2;

      iVar2 = *(int *)(iVar1 + 0x10);

    } while (iVar2 != param_4);

    if (iVar1 != 0) {

      *(undefined4 *)(iVar1 + 0x10) = *(undefined4 *)(iVar2 + 0x10);

      *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

      return;

    }

  }

  *param_3 = *(int *)(iVar2 + 0x10);

  *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

  return;

}





// --- FUN_00406a10 at 0x00406A10 (size: 121) ---


void __fastcall FUN_00406a10(int param_1)



{

  int iVar1;

  void *pvVar2;

  void *pvVar3;

  void *pvVar4;

  int *piVar5;

  

  iVar1 = *(int *)(param_1 + 0x6c);

  do {

    if (iVar1 == 0) {

      return;

    }

    piVar5 = *(int **)(param_1 + 100);

    while (piVar5 != (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

      if (**(int **)(param_1 + 100) != 0) {

        piVar5 = *(int **)(param_1 + 100);

        pvVar4 = (void *)*piVar5;

        goto LAB_00406a4f;

      }

      piVar5 = *(int **)(param_1 + 100) + 1;

      *(int **)(param_1 + 100) = piVar5;

    }

    piVar5 = (int *)0x0;

    pvVar4 = (void *)0x0;

LAB_00406a4f:

    pvVar3 = (void *)*piVar5;

    if (pvVar3 == pvVar4) {

LAB_00406a62:

      *piVar5 = *(int *)((int)pvVar3 + 0x10);

    }

    else {

      do {

        pvVar2 = pvVar3;

        pvVar3 = *(void **)((int)pvVar2 + 0x10);

      } while (pvVar3 != pvVar4);

      if (pvVar2 == (void *)0x0) goto LAB_00406a62;

      *(undefined4 *)((int)pvVar2 + 0x10) = *(undefined4 *)((int)pvVar3 + 0x10);

    }

    *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

    if (pvVar4 != (void *)0x0) {

      operator_delete(pvVar4);

    }

    iVar1 = *(int *)(param_1 + 0x6c);

  } while( true );

}





// --- FUN_00406a90 at 0x00406A90 (size: 147) ---


void FUN_00406a90(undefined4 *param_1,undefined4 param_2,int *param_3,undefined4 *param_4)



{

  int *piVar1;

  undefined4 *puVar2;

  int *piVar3;

  undefined1 local_c [8];

  int local_4;

  

  piVar1 = param_3;

  if (param_3 != (int *)0x0) {

    piVar3 = (int *)0x0;

    FUN_00406440(local_c,param_2);

    puVar2 = param_4;

    if (local_4 != 0) {

      piVar3 = *(int **)(local_4 + 0x14);

    }

    if (param_4 != (undefined4 *)0x0) {

      if (piVar3 != (int *)0x0) {

        (**(code **)(*piVar3 + 0x10))();

      }

      *puVar2 = piVar3;

    }

    if (piVar3 != piVar1) {

      if (piVar3 != (int *)0x0) {

        (**(code **)(*piVar3 + 0x14))();

      }

      (**(code **)(*piVar1 + 0x10))();

      FUN_00406940(param_2,&param_3);

    }

    *param_1 = 0;

    return;

  }

  *param_1 = 0x80004005;

  return;

}





// --- FUN_00406b30 at 0x00406B30 (size: 85) ---


int FUN_00406b30(undefined4 param_1)



{

  undefined4 local_c;

  undefined4 local_8;

  int local_4;

  

  FUN_00406440(&local_c,param_1);

  if (local_4 != 0) {

    FUN_004069d0(local_c,local_8,local_4);

    return local_4;

  }

  return 0;

}





// --- FUN_00406b90 at 0x00406B90 (size: 82) ---


undefined4 * __thiscall FUN_00406b90(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_007952e0;

  FUN_00406a10();

  param_1[1] = &PTR_FUN_007952dc;

  if ((undefined4 *)param_1[0x19] != param_1 + 2) {

    operator_delete__((undefined4 *)param_1[0x19]);

  }

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  param_1[0x1c] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_00406bf0 at 0x00406BF0 (size: 147) ---


void __fastcall FUN_00406bf0(undefined4 *param_1)



{

  int iVar1;

  int *piVar2;

  int iVar3;

  int *piVar4;

  undefined1 local_c [12];

  

  piVar2 = (int *)FUN_004063f0(local_c);

  iVar1 = *piVar2;

  piVar4 = (int *)piVar2[1];

  iVar3 = piVar2[2];

  while (iVar3 != 0) {

    do {

      (**(code **)(**(int **)(iVar3 + 0x14) + 0x14))();

      iVar3 = *(int *)(iVar3 + 0x10);

    } while (iVar3 != 0);

    do {

      piVar4 = piVar4 + 1;

      if (piVar4 == (int *)(*(int *)(iVar1 + 0x60) + *(int *)(iVar1 + 0x68) * 4)) goto LAB_00406c46;

    } while (*piVar4 == 0);

    iVar3 = *piVar4;

  }

LAB_00406c46:

  *param_1 = &PTR_FUN_007952e0;

  FUN_00406a10();

  param_1[1] = &PTR_FUN_007952dc;

  if ((undefined4 *)param_1[0x19] != param_1 + 2) {

    operator_delete__((undefined4 *)param_1[0x19]);

  }

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  param_1[0x1c] = 0;

  return;

}





// --- FUN_00406c90 at 0x00406C90 (size: 119) ---


void FUN_00406c90(undefined4 *param_1,undefined4 param_2,int *param_3,undefined4 *param_4)



{

  void *pvVar1;

  int *piVar2;

  undefined1 local_c [8];

  int local_4;

  

  piVar2 = (int *)0x0;

  FUN_00406440(local_c,param_2);

  if (local_4 != 0) {

    piVar2 = *(int **)(local_4 + 0x14);

  }

  if (param_4 != (undefined4 *)0x0) {

    *param_4 = piVar2;

    (**(code **)(*piVar2 + 0x10))();

  }

  if ((param_3 == (int *)0x0) || (piVar2 == param_3)) {

    pvVar1 = (void *)FUN_00406b30(param_2);

    if (pvVar1 != (void *)0x0) {

      operator_delete(pvVar1);

    }

    if (piVar2 != (int *)0x0) {

      (**(code **)(*piVar2 + 0x14))();

    }

  }

  *param_1 = 0;

  return;

}





// --- FUN_00406d10 at 0x00406D10 (size: 78) ---


undefined4 * FUN_00406d10(void)



{

  undefined4 *puVar1;

  

  if (DAT_00837744 != '\0') {

    return (undefined4 *)0x0;

  }

  if (DAT_00837740 == (undefined4 *)0x0) {

    puVar1 = (undefined4 *)FUN_005df0f5(0x74);

    if (puVar1 != (undefined4 *)0x0) {

      *puVar1 = &PTR_FUN_007952e0;

      FUN_004066e0(0);

      *puVar1 = &PTR_FUN_007952e0;

      DAT_00837740 = puVar1;

      return puVar1;

    }

    DAT_00837740 = (undefined4 *)0x0;

  }

  return DAT_00837740;

}





// --- FUN_00406d60 at 0x00406D60 (size: 13) ---


void __fastcall FUN_00406d60(undefined4 *param_1)



{

  *param_1 = 0;

  param_1[1] = 0;

  param_1[2] = 0;

  return;

}





// --- FUN_00406d70 at 0x00406D70 (size: 14) ---


undefined4 __fastcall FUN_00406d70(int param_1)



{

  int iVar1;

  

  iVar1 = *(int *)(param_1 + 8);

  if (iVar1 != 0) {

    return CONCAT31((int3)((uint)iVar1 >> 8),*(undefined1 *)(iVar1 + 0x11));

  }

  return 1;

}





// --- FUN_00406d80 at 0x00406D80 (size: 16) ---


int __fastcall FUN_00406d80(int *param_1)



{

  if (param_1[2] != 0) {

    return *(int *)(param_1[2] + 8) + *param_1;

  }

  return 0;

}





// --- FUN_00406d90 at 0x00406D90 (size: 22) ---


undefined4 __fastcall FUN_00406d90(int param_1)



{

  int iVar1;

  

  iVar1 = *(int *)(param_1 + 8);

  if (iVar1 != 0) {

    *(undefined1 *)(iVar1 + 0x10) = 0;

    *(undefined1 *)(iVar1 + 0x11) = 0;

    return *(undefined4 *)(iVar1 + 8);

  }

  return 0;

}





// --- FUN_00406db0 at 0x00406DB0 (size: 4) ---


undefined4 __fastcall FUN_00406db0(int param_1)



{

  return *(undefined4 *)(param_1 + 4);

}





// --- FUN_00406dc0 at 0x00406DC0 (size: 14) ---


undefined4 __fastcall FUN_00406dc0(int param_1)



{

  if (*(int *)(param_1 + 8) != 0) {

    return *(undefined4 *)(*(int *)(param_1 + 8) + 4);

  }

  return 0;

}





// --- FUN_00406dd0 at 0x00406DD0 (size: 73) ---


void __fastcall FUN_00406dd0(LONG *param_1)



{

  int iVar1;

  uint uVar2;

  

  uVar2 = 0;

  iVar1 = InterlockedExchange(param_1,1);

  while (iVar1 != 0) {

    iVar1 = *param_1;

    while (iVar1 != 0) {

      uVar2 = uVar2 + 1;

      if (0xfffff < uVar2) {

        Sleep(0);

        uVar2 = 0;

      }

      iVar1 = *param_1;

    }

    iVar1 = InterlockedExchange(param_1,1);

  }

  return;

}





// --- FUN_00406e20 at 0x00406E20 (size: 96) ---


uint FUN_00406e20(uint param_1)



{

  int iVar1;

  uint uVar2;

  uint uVar3;

  

  if (0x40000 < param_1) {

    return (param_1 + 0x3ffff) - (param_1 + 0x3ffff & 0x3ffff);

  }

  if (param_1 < 0x10) {

    return 0x10;

  }

  iVar1 = 0x1f;

  if (param_1 != 0) {

    for (; param_1 >> iVar1 == 0; iVar1 = iVar1 + -1) {

    }

  }

  uVar3 = 1 << ((byte)iVar1 & 0x1f);

  uVar2 = uVar3;

  if (0x1800 < uVar3) {

    uVar2 = uVar3 + 0xc00;

  }

  if (uVar2 < param_1) {

    uVar2 = uVar2 + uVar3;

  }

  return uVar2;

}





// --- FUN_00406e80 at 0x00406E80 (size: 219) ---


void __fastcall FUN_00406e80(int param_1)



{

  int iVar1;

  undefined4 uVar2;

  uint uVar3;

  uint uVar4;

  uint uVar5;

  

  if (*(char *)(param_1 + 0x10) != '\0') {

    if (*(char *)(param_1 + 0x12) != '\0') {

      if (((*(uint *)(param_1 + 0xc) != 0) && (*(uint *)(param_1 + 0xc) < 0x200000)) &&

         (DAT_00837798 != (LONG *)0x0)) {

        FUN_00406dd0();

        uVar3 = 0;

        uVar4 = DAT_0083775c;

        uVar5 = DAT_0083779c;

        if (DAT_0083779c < 8) {

          (&DAT_00837758)[DAT_0083779c * 2] = 0;

          DAT_0083779c = DAT_0083779c + 1;

        }

        else {

          while (1 < uVar5) {

            iVar1 = uVar5 * 8;

            uVar5 = uVar5 - 1;

            if (*(uint *)(&DAT_00837754 + iVar1) < uVar4) {

              uVar3 = uVar5;

              uVar4 = *(uint *)(&DAT_00837754 + iVar1);

            }

          }

          uVar5 = 0xffffffff;

          if (uVar4 < *(uint *)(param_1 + 0xc)) {

            uVar5 = uVar3;

          }

        }

        if (uVar5 < DAT_0083779c) {

          uVar2 = *(undefined4 *)(param_1 + 8);

          *(undefined4 *)(param_1 + 8) = (&DAT_00837758)[uVar5 * 2];

          (&DAT_00837758)[uVar5 * 2] = uVar2;

          (&DAT_0083775c)[uVar5 * 2] = *(undefined4 *)(param_1 + 0xc);

        }

        InterlockedExchange(DAT_00837798,0);

      }

    }

    operator_delete__(*(void **)(param_1 + 8));

  }

  *(undefined4 *)(param_1 + 8) = 0;

  *(undefined4 *)(param_1 + 0xc) = 0;

  return;

}





// --- FUN_00406f60 at 0x00406F60 (size: 43) ---


undefined4 * __thiscall FUN_00406f60(undefined4 *param_1,undefined4 *param_2)



{

  int iVar1;

  

  *param_1 = *param_2;

  param_1[1] = param_2[1];

  iVar1 = param_2[2];

  param_1[2] = iVar1;

  if (iVar1 != 0) {

    InterlockedIncrement((LONG *)(iVar1 + 4));

  }

  return param_1;

}





// --- FUN_00406f90 at 0x00406F90 (size: 60) ---


void __fastcall FUN_00406f90(undefined4 *param_1)



{

  undefined4 *puVar1;

  LONG LVar2;

  

  puVar1 = (undefined4 *)param_1[2];

  if (puVar1 != (undefined4 *)0x0) {

    LVar2 = InterlockedDecrement(puVar1 + 1);

    if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

      (**(code **)*puVar1)(1);

    }

    param_1[2] = 0;

  }

  *param_1 = 0;

  param_1[1] = 0;

  return;

}





// --- FUN_00406fd0 at 0x00406FD0 (size: 42) ---


undefined4 * __thiscall FUN_00406fd0(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_007952f8;

  FUN_00406e80();

  *param_1 = &PTR_FUN_007952f4;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_00407000 at 0x00407000 (size: 76) ---


void FUN_00407000(void)



{

  int iVar1;

  

  if (DAT_00837798 != (void *)0x0) {

    operator_delete(DAT_00837798);

  }

  DAT_00837798 = (void *)0x0;

  for (iVar1 = DAT_0083779c; iVar1 != 0; iVar1 = iVar1 + -1) {

    operator_delete__((void *)(&DAT_00837750)[iVar1 * 2]);

  }

  DAT_0083779c = 0;

  return;

}





// --- FUN_00407060 at 0x00407060 (size: 101) ---


undefined4 * __thiscall FUN_00407060(undefined4 *param_1,undefined4 param_2,undefined4 param_3)



{

  undefined4 *puVar1;

  

  *param_1 = 0;

  param_1[1] = param_3;

  puVar1 = (undefined4 *)FUN_005df0f5(0x14);

  if (puVar1 == (undefined4 *)0x0) {

    puVar1 = (undefined4 *)0x0;

  }

  else {

    puVar1[1] = 1;

    *puVar1 = &PTR_FUN_007952f8;

    puVar1[2] = 0;

    puVar1[3] = 0;

    *(undefined1 *)(puVar1 + 4) = 1;

    *(undefined1 *)((int)puVar1 + 0x11) = 1;

    *(undefined1 *)((int)puVar1 + 0x12) = 0;

  }

  param_1[2] = puVar1;

  FUN_00406e80();

  puVar1[2] = param_2;

  puVar1[3] = param_3;

  *(undefined1 *)(puVar1 + 4) = 0;

  *(undefined1 *)((int)puVar1 + 0x11) = 0;

  return param_1;

}





// --- FUN_004070d0 at 0x004070D0 (size: 104) ---


undefined4 * __thiscall FUN_004070d0(undefined4 *param_1,undefined4 *param_2)



{

  undefined4 *puVar1;

  int iVar2;

  LONG LVar3;

  

  if (param_2 != param_1) {

    puVar1 = (undefined4 *)param_1[2];

    if (puVar1 != (undefined4 *)0x0) {

      LVar3 = InterlockedDecrement(puVar1 + 1);

      if ((LVar3 == 0) && (puVar1 != (undefined4 *)0x0)) {

        (**(code **)*puVar1)(1);

      }

      param_1[2] = 0;

    }

    *param_1 = 0;

    param_1[1] = 0;

    iVar2 = param_2[2];

    param_1[2] = iVar2;

    if (iVar2 != 0) {

      InterlockedIncrement((LONG *)(iVar2 + 4));

    }

    *param_1 = *param_2;

    param_1[1] = param_2[1];

  }

  return param_1;

}





// --- FUN_00407140 at 0x00407140 (size: 151) ---


int * __thiscall FUN_00407140(int *param_1,int *param_2,int param_3,int param_4)



{

  undefined4 *puVar1;

  LONG LVar2;

  

  if (param_1[2] == 0) {

    puVar1 = (undefined4 *)FUN_005df0f5(0x14);

    if (puVar1 == (undefined4 *)0x0) {

      puVar1 = (undefined4 *)0x0;

    }

    else {

      puVar1[1] = 1;

      *puVar1 = &PTR_FUN_007952f8;

      puVar1[2] = 0;

      puVar1[3] = 0;

      *(undefined1 *)(puVar1 + 4) = 1;

      *(undefined1 *)((int)puVar1 + 0x11) = 1;

      *(undefined1 *)((int)puVar1 + 0x12) = 0;

    }

    param_1[2] = (int)puVar1;

  }

  puVar1 = (undefined4 *)param_1[2];

  if (puVar1 != (undefined4 *)0x0) {

    InterlockedIncrement(puVar1 + 1);

  }

  *param_2 = *param_1 + param_3;

  param_2[1] = param_4;

  param_2[2] = (int)puVar1;

  if (puVar1 != (undefined4 *)0x0) {

    InterlockedIncrement(puVar1 + 1);

    LVar2 = InterlockedDecrement(puVar1 + 1);

    if (LVar2 == 0) {

      (**(code **)*puVar1)(1);

    }

  }

  return param_2;

}





// --- FUN_004071e0 at 0x004071E0 (size: 106) ---


void __fastcall FUN_004071e0(undefined4 *param_1)



{

  LONG LVar1;

  undefined4 *puVar2;

  

  puVar2 = (undefined4 *)param_1[2];

  if (puVar2 != (undefined4 *)0x0) {

    LVar1 = InterlockedDecrement(puVar2 + 1);

    if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

      (**(code **)*puVar2)(1);

    }

    param_1[2] = 0;

  }

  *param_1 = 0;

  param_1[1] = 0;

  puVar2 = (undefined4 *)FUN_005df0f5(0x14);

  if (puVar2 != (undefined4 *)0x0) {

    puVar2[2] = 0;

    puVar2[3] = 0;

    *(undefined1 *)((int)puVar2 + 0x12) = 0;

    puVar2[1] = 1;

    *puVar2 = &PTR_FUN_007952f8;

    *(undefined1 *)(puVar2 + 4) = 1;

    *(undefined1 *)((int)puVar2 + 0x11) = 1;

    param_1[2] = puVar2;

    return;

  }

  param_1[2] = 0;

  return;

}





// --- FUN_00407250 at 0x00407250 (size: 308) ---


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



void __thiscall FUN_00407250(int param_1,uint param_2)



{

  int iVar1;

  int iVar2;

  uint uVar3;

  uint uVar4;

  int iVar5;

  undefined4 *puVar6;

  undefined4 *puVar7;

  undefined4 *puVar8;

  

  if ((_DAT_008377a0 & 1) == 0) {

    _DAT_008377a0 = _DAT_008377a0 | 1;

    DAT_00837798 = (LONG *)FUN_005df0f5(0xc);

    if (DAT_00837798 == (LONG *)0x0) {

      DAT_00837798 = (LONG *)0x0;

      _atexit((_func_4879 *)&LAB_00726b50);

    }

    else {

      *DAT_00837798 = 0;

      DAT_00837798[1] = 0;

      DAT_00837798[2] = 0;

      _atexit((_func_4879 *)&LAB_00726b50);

    }

  }

  if (param_2 <= *(uint *)(param_1 + 0xc)) {

    return;

  }

  puVar6 = (undefined4 *)0x0;

  if (((*(char *)(param_1 + 0x12) != '\0') && (DAT_0083779c != 0)) && (DAT_00837798 != (LONG *)0x0))

  {

    FUN_00406dd0();

    iVar2 = DAT_0083779c;

    if (DAT_0083779c != 0) {

      do {

        if (iVar2 == 0) goto LAB_00407333;

        iVar2 = iVar2 + -1;

      } while ((uint)(&DAT_0083775c)[iVar2 * 2] < param_2);

      param_2 = (&DAT_0083775c)[iVar2 * 2];

      puVar6 = (undefined4 *)(&DAT_00837758)[iVar2 * 2];

      iVar1 = DAT_0083779c * 2;

      iVar5 = DAT_0083779c + -1;

      DAT_0083779c = iVar5;

      (&DAT_00837758)[iVar2 * 2] = (&DAT_00837750)[iVar1];

      (&DAT_0083775c)[iVar2 * 2] = (&DAT_0083775c)[iVar5 * 2];

    }

LAB_00407333:

    InterlockedExchange(DAT_00837798,0);

    if (puVar6 != (undefined4 *)0x0) goto LAB_0040734f;

  }

  puVar6 = (undefined4 *)thunk_FUN_005df0f5(param_2);

LAB_0040734f:

  uVar4 = *(uint *)(param_1 + 0xc);

  if (uVar4 != 0) {

    puVar7 = *(undefined4 **)(param_1 + 8);

    puVar8 = puVar6;

    for (uVar3 = uVar4 >> 2; uVar3 != 0; uVar3 = uVar3 - 1) {

      *puVar8 = *puVar7;

      puVar7 = puVar7 + 1;

      puVar8 = puVar8 + 1;

    }

    for (uVar4 = uVar4 & 3; uVar4 != 0; uVar4 = uVar4 - 1) {

      *(undefined1 *)puVar8 = *(undefined1 *)puVar7;

      puVar7 = (undefined4 *)((int)puVar7 + 1);

      puVar8 = (undefined4 *)((int)puVar8 + 1);

    }

    FUN_00406e80();

  }

  *(undefined4 **)(param_1 + 8) = puVar6;

  *(uint *)(param_1 + 0xc) = param_2;

  return;

}





// --- FUN_00407390 at 0x00407390 (size: 28) ---


undefined4 __thiscall FUN_00407390(int param_1,undefined4 param_2,int param_3)



{

  FUN_00407140(param_2,param_3,*(int *)(param_1 + 4) - param_3);

  return param_2;

}





// --- FUN_004073b0 at 0x004073B0 (size: 49) ---


void __thiscall FUN_004073b0(int param_1,undefined4 param_2,undefined4 param_3)



{

  int iVar1;

  

  FUN_004071e0();

  iVar1 = *(int *)(param_1 + 8);

  FUN_00406e80();

  *(undefined4 *)(iVar1 + 8) = param_2;

  *(undefined4 *)(iVar1 + 0xc) = param_3;

  *(undefined1 *)(iVar1 + 0x10) = 0;

  *(undefined1 *)(iVar1 + 0x11) = 0;

  *(undefined4 *)(param_1 + 4) = param_3;

  return;

}





// --- FUN_004073f0 at 0x004073F0 (size: 181) ---


undefined4 * __thiscall FUN_004073f0(int *param_1,undefined4 *param_2)



{

  int iVar1;

  LONG LVar2;

  uint uVar3;

  uint uVar4;

  undefined4 *puVar5;

  undefined4 *puVar6;

  undefined4 *puVar7;

  

  puVar7 = (undefined4 *)0x0;

  iVar1 = 0;

  puVar5 = (undefined4 *)0x0;

  if (param_1[2] != 0) {

    puVar5 = (undefined4 *)FUN_005df0f5(0x14);

    if (puVar5 == (undefined4 *)0x0) {

      puVar5 = (undefined4 *)0x0;

    }

    else {

      puVar5[1] = 1;

      *puVar5 = &PTR_FUN_007952f8;

      puVar5[2] = 0;

      puVar5[3] = 0;

      *(undefined1 *)(puVar5 + 4) = 1;

      *(undefined1 *)((int)puVar5 + 0x11) = 1;

      *(undefined1 *)((int)puVar5 + 0x12) = 0;

    }

    FUN_00407250(param_1[1]);

    if (param_1[2] == 0) {

      puVar6 = (undefined4 *)0x0;

    }

    else {

      puVar6 = (undefined4 *)(*(int *)(param_1[2] + 8) + *param_1);

    }

    if (puVar5 != (undefined4 *)0x0) {

      puVar7 = (undefined4 *)puVar5[2];

    }

    uVar4 = param_1[1];

    for (uVar3 = uVar4 >> 2; uVar3 != 0; uVar3 = uVar3 - 1) {

      *puVar7 = *puVar6;

      puVar6 = puVar6 + 1;

      puVar7 = puVar7 + 1;

    }

    for (uVar4 = uVar4 & 3; uVar4 != 0; uVar4 = uVar4 - 1) {

      *(undefined1 *)puVar7 = *(undefined1 *)puVar6;

      puVar6 = (undefined4 *)((int)puVar6 + 1);

      puVar7 = (undefined4 *)((int)puVar7 + 1);

    }

    iVar1 = param_1[1];

  }

  *param_2 = 0;

  param_2[1] = iVar1;

  param_2[2] = puVar5;

  if (puVar5 != (undefined4 *)0x0) {

    InterlockedIncrement(puVar5 + 1);

    LVar2 = InterlockedDecrement(puVar5 + 1);

    if (LVar2 == 0) {

      (**(code **)*puVar5)(1);

    }

  }

  return param_2;

}





// --- FUN_004074b0 at 0x004074B0 (size: 160) ---


void __thiscall FUN_004074b0(int *param_1,uint param_2,byte param_3)



{

  undefined4 *puVar1;

  int iVar2;

  

  if ((param_3 & 8) != 0) {

    *(undefined1 *)(param_1[2] + 0x12) = 1;

  }

  if ((uint)param_1[1] < param_2) {

    if (param_1[2] == 0) {

      puVar1 = (undefined4 *)FUN_005df0f5(0x14);

      if (puVar1 == (undefined4 *)0x0) {

        puVar1 = (undefined4 *)0x0;

      }

      else {

        puVar1[1] = 1;

        *puVar1 = &PTR_FUN_007952f8;

        puVar1[2] = 0;

        puVar1[3] = 0;

        *(undefined1 *)(puVar1 + 4) = 1;

        *(undefined1 *)((int)puVar1 + 0x11) = 1;

        *(undefined1 *)((int)puVar1 + 0x12) = 0;

      }

      param_1[2] = (int)puVar1;

    }

    if ((param_3 & 1) == 0) {

      iVar2 = *param_1 + param_2;

    }

    else {

      iVar2 = FUN_00406e20(*param_1 + param_2);

    }

    FUN_00407250(iVar2);

    param_1[1] = param_2;

  }

  if ((param_3 & 4) != 0) {

    *(undefined1 *)(param_1[2] + 0x11) = 0;

  }

  if ((param_3 & 2) != 0) {

    param_1[1] = param_2;

  }

  return;

}





// --- FUN_00407550 at 0x00407550 (size: 87) ---


void FUN_00407550(char *param_1,undefined4 param_2)



{

  undefined *puVar1;

  

  if ((param_1 != (char *)0x0) && (*param_1 != '\0')) {

    switch(param_2) {

    default:

      fputs(param_1,(FILE *)(_iob_exref + 0x20));

      return;

    case 1:

      puVar1 = &DAT_00795314;

      break;

    case 2:

    case 3:

      puVar1 = &DAT_0079530c;

    }

    FUN_004102a0("%s%s%s",puVar1,param_1,&DAT_00795304);

    return;

  }

  return;

}





// --- FUN_004075c0 at 0x004075C0 (size: 26) ---


int __thiscall FUN_004075c0(int *param_1,uint param_2)



{

  int iVar1;

  

  iVar1 = *param_1;

  if (*(uint *)(iVar1 + -4) <= param_2) {

    return iVar1 + -2 + *(uint *)(iVar1 + -4) * 2;

  }

  return iVar1 + param_2 * 2;

}





// --- FUN_00407680 at 0x00407680 (size: 74) ---


uint __fastcall FUN_00407680(undefined4 *param_1)



{

  wint_t *pwVar1;

  wint_t wVar2;

  uint uVar3;

  wint_t *pwVar4;

  

  pwVar4 = (wint_t *)*param_1;

  uVar3 = 0;

  wVar2 = *pwVar4;

  while (wVar2 != 0) {

    wVar2 = towlower(wVar2);

    uVar3 = uVar3 * 0x10 + (uint)wVar2;

    if ((uVar3 & 0xf0000000) != 0) {

      uVar3 = ((uVar3 & 0xf0000000) >> 0x18 ^ uVar3) & 0xfffffff;

    }

    pwVar1 = pwVar4 + 1;

    pwVar4 = pwVar4 + 1;

    wVar2 = *pwVar1;

  }

  return uVar3;

}





// --- FUN_004076d0 at 0x004076D0 (size: 64) ---


undefined4 * __thiscall FUN_004076d0(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_00795324;

  if ((undefined4 *)param_1[0x18] != param_1 + 1) {

    operator_delete__((undefined4 *)param_1[0x18]);

  }

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_00407710 at 0x00407710 (size: 64) ---


undefined4 * __thiscall FUN_00407710(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_00795328;

  if ((undefined4 *)param_1[0x18] != param_1 + 1) {

    operator_delete__((undefined4 *)param_1[0x18]);

  }

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_00407750 at 0x00407750 (size: 151) ---


undefined4 * __thiscall FUN_00407750(undefined4 *param_1,undefined4 *param_2)



{

  int iVar1;

  LONG LVar2;

  

  *param_1 = *param_2;

  *(undefined1 *)(param_1 + 1) = *(undefined1 *)(param_2 + 1);

  iVar1 = param_1[2];

  if (iVar1 != param_2[2]) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = param_2[2];

    param_1[2] = iVar1;

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

  }

  iVar1 = param_1[3];

  if (iVar1 != param_2[3]) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = param_2[3];

    param_1[3] = iVar1;

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

  }

  param_1[4] = param_2[4];

  param_1[5] = param_2[5];

  param_1[6] = param_2[6];

  return param_1;

}





// --- FUN_004077f0 at 0x004077F0 (size: 85) ---


uint FUN_004077f0(uint param_1)



{

  int iVar1;

  uint uVar2;

  uint uVar3;

  

  if (param_1 < 9) {

    return 8;

  }

  if (0x4000 < param_1) {

    if ((param_1 & 0x3fff) != 0) {

      param_1 = param_1 + (0x4000 - (param_1 & 0x3fff));

    }

    return param_1;

  }

  iVar1 = 0x1f;

  if (param_1 != 0) {

    for (; param_1 >> iVar1 == 0; iVar1 = iVar1 + -1) {

    }

  }

  uVar3 = 1 << ((byte)iVar1 & 0x1f);

  uVar2 = uVar3 * 2;

  if (param_1 <= uVar3) {

    uVar2 = param_1;

  }

  return uVar2;

}





// --- FUN_00407850 at 0x00407850 (size: 205) ---


void __fastcall FUN_00407850(int *param_1)



{

  int *piVar1;

  undefined *puVar2;

  undefined *puVar3;

  uint uVar4;

  LONG LVar5;

  undefined4 *puVar6;

  

  param_1[2] = 0;

  if ((param_1[1] & 0x80000000U) != 0x80000000) {

    if (*param_1 != 0) {

      uVar4 = param_1[1] & 0x7fffffff;

      puVar3 = PTR_DAT_00818340;

      while (uVar4 = uVar4 - 1, PTR_DAT_00818340 = puVar3, -1 < (int)uVar4) {

        InterlockedIncrement((LONG *)(puVar3 + -0x10));

        piVar1 = (int *)(*param_1 + uVar4 * 4);

        puVar2 = (undefined *)*piVar1;

        if (puVar2 != puVar3) {

          LVar5 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

          if ((LVar5 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

            (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

          }

          *piVar1 = (int)puVar3;

          InterlockedIncrement((LONG *)(puVar3 + -0x10));

        }

        puVar6 = (undefined4 *)(puVar3 + -0x14);

        LVar5 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

        puVar3 = PTR_DAT_00818340;

        if ((LVar5 == 0) && (puVar6 != (undefined4 *)0x0)) {

          (**(code **)*puVar6)(1);

          puVar3 = PTR_DAT_00818340;

        }

      }

    }

    return;

  }

  if (*param_1 != 0) {

    FUN_00407920(3);

  }

  *param_1 = 0;

  param_1[1] = 0;

  return;

}





// --- FUN_00407920 at 0x00407920 (size: 167) ---


int * __thiscall FUN_00407920(int *param_1,byte param_2)



{

  int *piVar1;

  LONG LVar2;

  undefined4 *puVar3;

  int *piVar4;

  int local_4;

  

  if ((param_2 & 2) == 0) {

    puVar3 = (undefined4 *)(*param_1 + -0x14);

    LVar2 = InterlockedDecrement((LONG *)(*param_1 + -0x10));

    if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

      (**(code **)*puVar3)(1);

    }

    if ((param_2 & 1) != 0) {

      operator_delete(param_1);

    }

    return param_1;

  }

  local_4 = param_1[-1];

  piVar4 = param_1 + local_4;

  if (-1 < local_4 + -1) {

    do {

      piVar1 = piVar4 + -1;

      piVar4 = piVar4 + -1;

      puVar3 = (undefined4 *)(*piVar1 + -0x14);

      LVar2 = InterlockedDecrement((LONG *)(*piVar1 + -0x10));

      if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

        (**(code **)*puVar3)(1);

      }

      local_4 = local_4 + -1;

    } while (local_4 != 0);

  }

  if ((param_2 & 1) != 0) {

    operator_delete__(param_1 + -1);

  }

  return param_1 + -1;

}





// --- FUN_004079d0 at 0x004079D0 (size: 89) ---


void __fastcall FUN_004079d0(int *param_1)



{

  int iVar1;

  

  param_1[2] = 0;

  if ((param_1[1] & 0x80000000U) == 0x80000000) {

    operator_delete__((void *)*param_1);

    *param_1 = 0;

    param_1[1] = 0;

    return;

  }

  if (*param_1 != 0) {

    iVar1 = (param_1[1] & 0x7fffffffU) - 1;

    while (-1 < iVar1) {

      iVar1 = iVar1 + -1;

      *(undefined4 *)(*param_1 + 4 + iVar1 * 4) = 0;

    }

  }

  return;

}





// --- FUN_00407a40 at 0x00407A40 (size: 205) ---


void __fastcall FUN_00407a40(int *param_1)



{

  int *piVar1;

  undefined *puVar2;

  undefined *puVar3;

  uint uVar4;

  LONG LVar5;

  undefined4 *puVar6;

  

  param_1[2] = 0;

  if ((param_1[1] & 0x80000000U) != 0x80000000) {

    if (*param_1 != 0) {

      uVar4 = param_1[1] & 0x7fffffff;

      puVar3 = PTR_DAT_00818344;

      while (uVar4 = uVar4 - 1, PTR_DAT_00818344 = puVar3, -1 < (int)uVar4) {

        InterlockedIncrement((LONG *)(puVar3 + -0x10));

        piVar1 = (int *)(*param_1 + uVar4 * 4);

        puVar2 = (undefined *)*piVar1;

        if (puVar2 != puVar3) {

          LVar5 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

          if ((LVar5 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

            (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

          }

          *piVar1 = (int)puVar3;

          InterlockedIncrement((LONG *)(puVar3 + -0x10));

        }

        puVar6 = (undefined4 *)(puVar3 + -0x14);

        LVar5 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

        puVar3 = PTR_DAT_00818344;

        if ((LVar5 == 0) && (puVar6 != (undefined4 *)0x0)) {

          (**(code **)*puVar6)(1);

          puVar3 = PTR_DAT_00818344;

        }

      }

    }

    return;

  }

  if (*param_1 != 0) {

    FUN_00407920(3);

  }

  *param_1 = 0;

  param_1[1] = 0;

  return;

}





// --- FUN_00407b10 at 0x00407B10 (size: 54) ---


undefined4 * __fastcall FUN_00407b10(undefined4 *param_1)



{

  LONG *pLVar1;

  

  *param_1 = 0;

  pLVar1 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[2] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar1);

  pLVar1 = (LONG *)(PTR_DAT_00818344 + -0x10);

  param_1[3] = PTR_DAT_00818344;

  InterlockedIncrement(pLVar1);

  return param_1;

}





// --- FUN_00407b50 at 0x00407B50 (size: 475) ---


void __thiscall FUN_00407b50(int *param_1,int param_2,int param_3,int param_4)



{

  int iVar1;

  uint uVar2;

  undefined1 *puVar3;

  undefined4 uVar4;

  LONG LVar5;

  uint uVar6;

  uint uVar7;

  undefined4 *puVar8;

  uint uStack_148;

  int iStack_144;

  undefined1 *puStack_140;

  undefined4 uStack_13c;

  char *_Format;

  char cVar9;

  undefined1 auStack_114 [7];

  undefined1 local_10d;

  char local_108 [260];

  

  if (*(int *)(param_1[2] + -4) == 1) {

    local_10d = 0x20;

  }

  else {

    puVar3 = (undefined1 *)param_1[2];

    if (*(int *)(puVar3 + -4) == 0) {

      puVar3 = puVar3 + -1;

    }

    local_10d = *puVar3;

  }

  if (*(int *)(param_2 + -4) == 1) {

    sprintf(local_108,"  ");

  }

  else {

    sprintf(local_108,"%c%s");

  }

  cVar9 = (char)((uint)local_108 >> 0x18);

  (**(code **)(*param_1 + 0x28))();

  if ((*(int *)(param_2 + -4) == 1) || (*(int *)(param_3 + -4) == 1)) {

    _Format = "  ";

  }

  else {

    _Format = ", ";

  }

  uStack_13c = 0x407c02;

  sprintf(&stack0xfffffee8,_Format);

  uStack_13c = 0x16;

  puStack_140 = &stack0xfffffee8;

  iStack_144 = 0x407c16;

  uVar2 = (**(code **)(*param_1 + 0x28))();

  if (*(int *)(param_3 + -4) != 1) {

    uStack_148 = (uint)cVar9;

    iStack_144 = param_3;

    sprintf(&stack0xfffffed8,"%c%c%s",uStack_148);

    iStack_144 = 3;

    uStack_148 = uVar2;

    uVar2 = (**(code **)(*param_1 + 0x28))(&stack0xfffffed8,0x16);

  }

  puVar3 = &stack0xfffffed8;

  if (uVar2 < 0x14) {

    iVar1 = -uVar2;

    uVar6 = iVar1 + 0x14;

    puVar8 = (undefined4 *)&stack0xfffffed8;

    for (uVar7 = uVar6 >> 2; uVar7 != 0; uVar7 = uVar7 - 1) {

      *puVar8 = 0x20202020;

      puVar8 = puVar8 + 1;

    }

    for (uVar7 = uVar6 & 3; uVar7 != 0; uVar7 = uVar7 - 1) {

      *(undefined1 *)puVar8 = 0x20;

      puVar8 = (undefined4 *)((int)puVar8 + 1);

    }

    uVar2 = uVar2 + uVar6;

    puVar3 = auStack_114 + iVar1;

  }

  iStack_144 = 0;

  *puVar3 = 0x3a;

  puVar3[1] = 0x20;

  puVar3[2] = 0;

  uStack_148 = uVar2;

  uVar4 = (**(code **)(*param_1 + 0x28))(&stack0xfffffed8,0x16);

  (**(code **)(*param_1 + 0x28))(param_4,0x16,uVar4,4);

  uStack_148 = CONCAT22(uStack_148._2_2_,10);

  (**(code **)(*param_1 + 0x24))(&uStack_148,0);

  LVar5 = InterlockedDecrement((LONG *)(param_2 + -0x10));

  if ((LVar5 == 0) && ((undefined4 *)(param_2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(param_2 + -0x14))(1);

  }

  LVar5 = InterlockedDecrement((LONG *)(param_3 + -0x10));

  if ((LVar5 == 0) && ((undefined4 *)(param_3 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(param_3 + -0x14))(1);

  }

  LVar5 = InterlockedDecrement((LONG *)(param_4 + -0x10));

  if ((LVar5 == 0) && ((undefined4 *)(param_4 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(param_4 + -0x14))(1);

  }

  return;

}





// --- FUN_00407d30 at 0x00407D30 (size: 71) ---


void __thiscall FUN_00407d30(int param_1,int *param_2)



{

  int iVar1;

  LONG LVar2;

  

  iVar1 = *(int *)(param_1 + 4);

  if (iVar1 != *param_2) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = *param_2;

    *(int *)(param_1 + 4) = iVar1;

                    /* WARNING: Could not recover jumptable at 0x00407d6c. Too many branches */

                    /* WARNING: Treating indirect jump as call */

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

    return;

  }

  return;

}





// --- FUN_00407d80 at 0x00407D80 (size: 185) ---


void * __thiscall FUN_00407d80(void *param_1,byte param_2)



{

  int *piVar1;

  LONG LVar2;

  int iVar3;

  undefined4 *puVar4;

  int *piVar5;

  

  if ((param_2 & 2) == 0) {

    FUN_00402280();

    if ((param_2 & 1) != 0) {

      operator_delete(param_1);

    }

    return param_1;

  }

  iVar3 = *(int *)((int)param_1 + -4);

  if (-1 < iVar3 + -1) {

    piVar5 = (int *)((int)param_1 + iVar3 * 0x1c + 8);

    do {

      piVar1 = piVar5 + -6;

      piVar5 = piVar5 + -7;

      puVar4 = (undefined4 *)(*piVar1 + -0x14);

      LVar2 = InterlockedDecrement((LONG *)(*piVar1 + -0x10));

      if ((LVar2 == 0) && (puVar4 != (undefined4 *)0x0)) {

        (**(code **)*puVar4)(1);

      }

      puVar4 = (undefined4 *)(*piVar5 + -0x14);

      LVar2 = InterlockedDecrement((LONG *)(*piVar5 + -0x10));

      if ((LVar2 == 0) && (puVar4 != (undefined4 *)0x0)) {

        (**(code **)*puVar4)(1);

      }

      iVar3 = iVar3 + -1;

    } while (iVar3 != 0);

  }

  if ((param_2 & 1) != 0) {

    operator_delete__((void *)((int)param_1 + -4));

  }

  return (void *)((int)param_1 + -4);

}





// --- FUN_00407e40 at 0x00407E40 (size: 198) ---


void __thiscall FUN_00407e40(uint *param_1,wchar_t *param_2)



{

  uint uVar1;

  undefined *puVar2;

  size_t sVar3;

  LONG LVar4;

  

  if ((param_2 == (wchar_t *)0x0) || (*param_2 == L'\0')) {

    uVar1 = *param_1;

    if ((undefined *)(-(uint)(uVar1 != 0x14) & uVar1) != PTR_DAT_00818340) {

      LVar4 = InterlockedDecrement((LONG *)(uVar1 - 0x10));

      if ((LVar4 == 0) && ((undefined4 *)(uVar1 - 0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(uVar1 - 0x14))(1);

      }

      puVar2 = PTR_DAT_00818340;

      *param_1 = (uint)PTR_DAT_00818340;

                    /* WARNING: Could not recover jumptable at 0x00407f00. Too many branches */

                    /* WARNING: Treating indirect jump as call */

      InterlockedIncrement((LONG *)(puVar2 + -0x10));

      return;

    }

  }

  else {

    sVar3 = wcslen(param_2);

    uVar1 = *param_1;

    if ((*(int *)(uVar1 - 0x10) == 1) && (sVar3 < *(uint *)(uVar1 - 0xc))) {

      *(undefined4 *)(uVar1 - 8) = 0xffffffff;

      *(size_t *)(*param_1 - 4) = sVar3 + 1;

    }

    else {

      LVar4 = InterlockedDecrement((LONG *)(uVar1 - 0x10));

      if ((LVar4 == 0) && ((undefined4 *)(uVar1 - 0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(uVar1 - 0x14))(1);

      }

      FUN_004022d0(sVar3);

    }

    wcsncpy((wchar_t *)*param_1,param_2,sVar3 + 1);

  }

  return;

}





// --- FUN_00407f10 at 0x00407F10 (size: 193) ---


undefined4 __thiscall FUN_00407f10(int *param_1,uint param_2)



{

  uint *puVar1;

  int iVar2;

  uint *puVar3;

  

  if (param_2 < (uint)param_1[2]) {

    return 0;

  }

  if ((param_1[1] & 0x7fffffffU) < param_2) {

    if (param_2 != 0) {

      puVar3 = (uint *)thunk_FUN_005df0f5(param_2 * 4 + 4);

      if (puVar3 != (uint *)0x0) {

        puVar1 = puVar3 + 1;

        *puVar3 = param_2;

        FUN_00401000(puVar1,4,param_2,FUN_00401a60);

        if (puVar1 != (uint *)0x0) {

          if (*param_1 != 0) {

            iVar2 = param_1[2];

            while (iVar2 = iVar2 + -1, -1 < iVar2) {

              FUN_00402070(*param_1 + iVar2 * 4);

            }

            if (((param_1[1] & 0x80000000U) == 0x80000000) && (*param_1 != 0)) {

              FUN_00407920(3);

            }

          }

          *param_1 = (int)puVar1;

          param_1[1] = param_2 | 0x80000000;

          return 1;

        }

      }

      return 0;

    }

    FUN_00407850();

  }

  return 1;

}





// --- FUN_00407fe0 at 0x00407FE0 (size: 219) ---


undefined1 __thiscall FUN_00407fe0(int *param_1,uint param_2,char param_3)



{

  LONG *lpAddend;

  int iVar1;

  undefined *puVar2;

  undefined *puVar3;

  char cVar4;

  uint uVar5;

  LONG LVar6;

  

  if ((param_1[1] & 0x7fffffffU) < param_2) {

    uVar5 = param_2;

    if (param_3 == '\0') {

      uVar5 = FUN_004077f0(param_2);

    }

    cVar4 = FUN_00407f10(uVar5);

    if (cVar4 == '\0') {

      return 0;

    }

  }

  else {

    _param_3 = param_2;

    if (param_2 < (uint)param_1[2]) {

      do {

        puVar3 = PTR_DAT_00818340;

        lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

        InterlockedIncrement(lpAddend);

        iVar1 = *param_1;

        puVar2 = *(undefined **)(iVar1 + _param_3 * 4);

        if (puVar2 != puVar3) {

          LVar6 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

          if ((LVar6 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

            (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

          }

          *(undefined **)(iVar1 + _param_3 * 4) = puVar3;

          InterlockedIncrement(lpAddend);

        }

        LVar6 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

        if ((LVar6 == 0) && ((undefined4 *)(puVar3 + -0x14) != (undefined4 *)0x0)) {

          (*(code *)**(undefined4 **)(puVar3 + -0x14))(1);

        }

        _param_3 = _param_3 + 1;

      } while (_param_3 < (uint)param_1[2]);

    }

  }

  param_1[2] = param_2;

  return 1;

}





// --- FUN_004080c0 at 0x004080C0 (size: 91) ---


void __fastcall FUN_004080c0(undefined4 *param_1)



{

  undefined4 *puVar1;

  LONG LVar2;

  uint uVar3;

  uint uVar4;

  undefined4 *puVar5;

  undefined4 *puVar6;

  

  puVar1 = (undefined4 *)*param_1;

  if (puVar1[-4] == 1) {

    puVar1[-2] = 0xffffffff;

    return;

  }

  FUN_00401280(puVar1[-1] + -1);

  uVar4 = ((undefined4 *)*param_1)[-1];

  puVar6 = (undefined4 *)*param_1;

  puVar5 = puVar1;

  for (uVar3 = uVar4 >> 2; uVar3 != 0; uVar3 = uVar3 - 1) {

    *puVar6 = *puVar5;

    puVar6 = puVar6 + 1;

    puVar5 = puVar5 + 1;

  }

  for (uVar4 = uVar4 & 3; uVar4 != 0; uVar4 = uVar4 - 1) {

    *(undefined1 *)puVar6 = *(undefined1 *)puVar5;

    puVar5 = (undefined4 *)((int)puVar5 + 1);

    puVar6 = (undefined4 *)((int)puVar6 + 1);

  }

  LVar2 = InterlockedDecrement(puVar1 + -4);

  if ((LVar2 == 0) && (puVar1 + -5 != (undefined4 *)0x0)) {

    (**(code **)puVar1[-5])(1);

  }

  return;

}





// --- FUN_00408120 at 0x00408120 (size: 245) ---


void __fastcall FUN_00408120(int *param_1)



{

  LONG LVar1;

  undefined4 *puVar2;

  uint local_20;

  undefined4 local_1c [2];

  undefined *local_14;

  undefined *local_10;

  

  param_1[2] = 0;

  if ((param_1[1] & 0x80000000U) != 0x80000000) {

    if ((*param_1 != 0) && (local_20 = param_1[1] & 0x7fffffff, -1 < (int)(local_20 - 1))) {

      do {

        local_14 = PTR_DAT_00818344;

        local_1c[0] = 0;

        InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

        local_10 = PTR_DAT_00818344;

        InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

        FUN_00407750(local_1c);

        puVar2 = (undefined4 *)(local_10 + -0x14);

        LVar1 = InterlockedDecrement((LONG *)(local_10 + -0x10));

        if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

          (**(code **)*puVar2)(1);

        }

        puVar2 = (undefined4 *)(local_14 + -0x14);

        LVar1 = InterlockedDecrement((LONG *)(local_14 + -0x10));

        if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

          (**(code **)*puVar2)(1);

        }

        local_20 = local_20 - 1;

      } while (local_20 != 0);

    }

    return;

  }

  if (*param_1 != 0) {

    FUN_00407d80(3);

  }

  *param_1 = 0;

  param_1[1] = 0;

  return;

}





// --- FUN_00408220 at 0x00408220 (size: 158) ---


undefined4 __thiscall FUN_00408220(int *param_1,uint param_2)



{

  int iVar1;

  int iVar2;

  

  if (param_2 < (uint)param_1[2]) {

    return 0;

  }

  if ((param_1[1] & 0x7fffffffU) < param_2) {

    if (param_2 != 0) {

      iVar1 = thunk_FUN_005df0f5(param_2 * 4);

      if (iVar1 == 0) {

        return 0;

      }

      if (*param_1 != 0) {

        iVar2 = param_1[2] + -1;

        while (-1 < iVar2) {

          iVar2 = iVar2 + -1;

          *(undefined4 *)(iVar1 + 4 + iVar2 * 4) = *(undefined4 *)(*param_1 + 4 + iVar2 * 4);

        }

        if ((param_1[1] & 0x80000000U) == 0x80000000) {

          operator_delete__((void *)*param_1);

        }

      }

      *param_1 = iVar1;

      param_1[1] = param_2 | 0x80000000;

      return 1;

    }

    FUN_004079d0();

  }

  return 1;

}





// --- FUN_004082c0 at 0x004082C0 (size: 193) ---


undefined4 __thiscall FUN_004082c0(int *param_1,uint param_2)



{

  uint *puVar1;

  int iVar2;

  uint *puVar3;

  

  if (param_2 < (uint)param_1[2]) {

    return 0;

  }

  if ((param_1[1] & 0x7fffffffU) < param_2) {

    if (param_2 != 0) {

      puVar3 = (uint *)thunk_FUN_005df0f5(param_2 * 4 + 4);

      if (puVar3 != (uint *)0x0) {

        puVar1 = puVar3 + 1;

        *puVar3 = param_2;

        FUN_00401000(puVar1,4,param_2,FUN_00401a40);

        if (puVar1 != (uint *)0x0) {

          if (*param_1 != 0) {

            iVar2 = param_1[2];

            while (iVar2 = iVar2 + -1, -1 < iVar2) {

              FUN_00402070(*param_1 + iVar2 * 4);

            }

            if (((param_1[1] & 0x80000000U) == 0x80000000) && (*param_1 != 0)) {

              FUN_00407920(3);

            }

          }

          *param_1 = (int)puVar1;

          param_1[1] = param_2 | 0x80000000;

          return 1;

        }

      }

      return 0;

    }

    FUN_00407a40();

  }

  return 1;

}





// --- FUN_00408390 at 0x00408390 (size: 93) ---


void __fastcall FUN_00408390(undefined4 *param_1)



{

  undefined4 *puVar1;

  LONG LVar2;

  uint uVar3;

  uint uVar4;

  undefined4 *puVar5;

  undefined4 *puVar6;

  

  puVar1 = (undefined4 *)*param_1;

  if (puVar1[-4] == 1) {

    puVar1[-2] = 0xffffffff;

    return;

  }

  FUN_004022d0(puVar1[-1] + -1);

  uVar4 = ((undefined4 *)*param_1)[-1] * 2;

  puVar6 = (undefined4 *)*param_1;

  puVar5 = puVar1;

  for (uVar3 = uVar4 >> 2; uVar3 != 0; uVar3 = uVar3 - 1) {

    *puVar6 = *puVar5;

    puVar6 = puVar6 + 1;

    puVar5 = puVar5 + 1;

  }

  for (uVar4 = uVar4 & 3; uVar4 != 0; uVar4 = uVar4 - 1) {

    *(undefined1 *)puVar6 = *(undefined1 *)puVar5;

    puVar5 = (undefined4 *)((int)puVar5 + 1);

    puVar6 = (undefined4 *)((int)puVar6 + 1);

  }

  LVar2 = InterlockedDecrement(puVar1 + -4);

  if ((LVar2 == 0) && (puVar1 + -5 != (undefined4 *)0x0)) {

    (**(code **)puVar1[-5])(1);

  }

  return;

}





// --- FUN_004083f0 at 0x004083F0 (size: 389) ---


bool FUN_004083f0(uint *param_1,int *param_2)



{

  long *plVar1;

  uint uVar2;

  long lVar3;

  int iVar4;

  bool bVar5;

  bool bVar6;

  

  bVar6 = true;

  bVar5 = true;

  switch(*param_1 & 0xff) {

  case 0x11:

    if ((uint *)param_1[4] != (uint *)0x0) {

      *(uint *)param_1[4] = param_1[5];

      return true;

    }

    break;

  case 0x12:

  case 0x13:

  case 0x14:

  case 0x15:

  case 0x16:

  case 0x17:

  case 0x18:

  case 0x19:

  case 0x1a:

  case 0x1b:

  case 0x1c:

  case 0x1d:

  case 0x1e:

  case 0x1f:

  case 0x20:

  case 0x21:

  case 0x23:

  case 0x24:

  case 0x25:

  case 0x26:

  case 0x27:

  case 0x28:

  case 0x29:

  case 0x2a:

  case 0x2b:

  case 0x2c:

  case 0x2d:

  case 0x2e:

  case 0x2f:

  case 0x30:

  case 0x31:

  case 0x33:

  case 0x34:

  case 0x35:

  case 0x36:

  case 0x37:

  case 0x38:

  case 0x39:

  case 0x3a:

  case 0x3b:

  case 0x3c:

  case 0x3d:

  case 0x3e:

  case 0x3f:

  case 0x40:

  case 0x41:

  case 0x43:

  case 0x44:

  case 0x45:

  case 0x46:

  case 0x47:

  case 0x48:

  case 0x49:

  case 0x4a:

  case 0x4b:

  case 0x4c:

  case 0x4d:

  case 0x4e:

  case 0x4f:

  case 0x50:

  case 0x51:

  case 0x53:

  case 0x54:

  case 0x55:

  case 0x56:

  case 0x57:

  case 0x58:

  case 0x59:

  case 0x5a:

  case 0x5b:

  case 0x5c:

  case 0x5d:

  case 0x5e:

  case 0x5f:

  case 0x60:

  case 0x61:

  case 99:

  case 100:

  case 0x65:

  case 0x66:

  case 0x67:

  case 0x68:

  case 0x69:

  case 0x6a:

  case 0x6b:

  case 0x6c:

  case 0x6d:

  case 0x6e:

  case 0x6f:

  case 0x70:

  case 0x72:

  case 0x73:

  case 0x74:

  case 0x75:

  case 0x76:

  case 0x77:

  case 0x78:

  case 0x79:

  case 0x7a:

  case 0x7b:

  case 0x7c:

  case 0x7d:

  case 0x7e:

  case 0x7f:

  case 0x80:

  case 0x81:

    break;

  case 0x22:

    plVar1 = (long *)param_1[4];

    if (plVar1 != (long *)0x0) {

      lVar3 = strtol((char *)*param_2,(char **)0x0,0);

      *plVar1 = lVar3;

      return true;

    }

    break;

  case 0x32:

    if (param_1[4] != 0) {

      param_2 = (int *)*param_2;

      InterlockedIncrement((LONG *)((int)param_2 + -0x10));

      FUN_00402070(&param_2);

      FUN_004011b0();

      return true;

    }

    break;

  case 0x42:

    if ((param_1[4] != 0) && (iVar4 = sscanf((char *)*param_2,"%f",param_1[4]), iVar4 != 1)) {

      return false;

    }

    break;

  case 0x52:

    if ((param_1[4] != 0) && (iVar4 = sscanf((char *)*param_2,"%lf",param_1[4]), iVar4 != 1)) {

      return false;

    }

    break;

  case 0x62:

    if ((param_1[4] != 0) && (iVar4 = sscanf((char *)*param_2,"%hu",param_1[4]), iVar4 != 1)) {

      return false;

    }

    break;

  case 0x71:

    if (param_1[4] != 0) {

      *(bool *)param_1[4] = param_1[5] != 0;

      return true;

    }

    break;

  case 0x82:

    uVar2 = param_1[4];

    if (uVar2 != 0) {

      iVar4 = sscanf((char *)*param_2,"%d",&param_2);

      *(bool *)uVar2 = param_2 != (int *)0x0;

      bVar6 = iVar4 == 1;

    }

    break;

  default:

    goto switchD_00408413_default;

  }

  bVar5 = bVar6;

switchD_00408413_default:

  return bVar5;

}





// --- FUN_00408610 at 0x00408610 (size: 93) ---


void __thiscall FUN_00408610(int param_1,int *param_2,undefined4 *param_3)



{

  uint uVar1;

  int iVar2;

  undefined4 *puVar3;

  uint uVar4;

  int iVar5;

  

  uVar1 = *(uint *)(param_1 + 0x68);

  uVar4 = FUN_00407680();

  uVar4 = uVar4 % uVar1;

  iVar2 = *(int *)(param_1 + 0x60);

  puVar3 = *(undefined4 **)(iVar2 + uVar4 * 4);

  while ((puVar3 != (undefined4 *)0x0 &&

         (iVar5 = _wcsicmp((wchar_t *)*puVar3,(wchar_t *)*param_3), iVar5 != 0))) {

    puVar3 = (undefined4 *)puVar3[1];

  }

  param_2[2] = (int)puVar3;

  *param_2 = param_1;

  param_2[1] = iVar2 + uVar4 * 4;

  return;

}





// --- FUN_00408670 at 0x00408670 (size: 66) ---


undefined4 * FUN_00408670(undefined4 *param_1,undefined4 param_2,char *param_3)



{

  int iVar1;

  

  iVar1 = _vscprintf(param_3,&stack0x00000010);

  FUN_00401280(iVar1);

  _vsnprintf((char *)*param_1,iVar1 + 1,param_3,&stack0x00000010);

  return param_1;

}





// --- FUN_004086c0 at 0x004086C0 (size: 173) ---


undefined4 * __thiscall FUN_004086c0(int *param_1,undefined4 *param_2,int *param_3)



{

  undefined *_Dest;

  LONG LVar1;

  

  _Dest = PTR_DAT_00818340;

  InterlockedIncrement((LONG *)(PTR_DAT_00818340 + -0x10));

  LVar1 = InterlockedDecrement((LONG *)(_Dest + -0x10));

  if ((LVar1 == 0) && ((undefined4 *)(_Dest + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(_Dest + -0x14))(1);

  }

  FUN_004022d0(*(int *)(*param_3 + -4) + -2 + *(int *)(*param_1 + -4));

  wcscpy((wchar_t *)_Dest,(wchar_t *)*param_1);

  wcscpy((wchar_t *)(_Dest + *(int *)(*param_1 + -4) * 2 + -2),(wchar_t *)*param_3);

  *param_2 = _Dest;

  InterlockedIncrement((LONG *)(_Dest + -0x10));

  LVar1 = InterlockedDecrement((LONG *)(_Dest + -0x10));

  if ((LVar1 == 0) && ((undefined4 *)(_Dest + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(_Dest + -0x14))(1);

  }

  return param_2;

}





// --- FUN_00408770 at 0x00408770 (size: 95) ---


void __thiscall FUN_00408770(int *param_1,uint param_2,char param_3)



{

  uint uVar1;

  

  uVar1 = *(uint *)(*param_1 + -4);

  if ((param_2 < uVar1) && (*(char *)(*param_1 + param_2) != param_3)) {

    uVar1 = uVar1 - 1;

    if (param_2 == uVar1) {

      FUN_00404ef0(&param_3,1);

      return;

    }

    FUN_004080c0();

    *(char *)(param_2 + *param_1) = param_3;

    if ((param_3 == '\0') && (param_2 < uVar1)) {

      *(uint *)(*param_1 + -4) = param_2 + 1;

    }

  }

  return;

}





// --- FUN_004087d0 at 0x004087D0 (size: 35) ---


undefined4 __thiscall FUN_004087d0(undefined4 param_1,int *param_2)



{

  int iVar1;

  

  iVar1 = *(int *)(*param_2 + -4);

  if (iVar1 != 1) {

    FUN_00404ef0(*param_2,iVar1 + -1);

  }

  return param_1;

}





// --- FUN_00408800 at 0x00408800 (size: 35) ---


undefined4 __thiscall FUN_00408800(undefined4 param_1,int *param_2)



{

  int iVar1;

  

  iVar1 = *(int *)(*param_2 + -4);

  if (iVar1 != 1) {

    FUN_00402490(*param_2,iVar1 + -1);

  }

  return param_1;

}





// --- FUN_00408830 at 0x00408830 (size: 224) ---


undefined4 __thiscall FUN_00408830(int *param_1,uint param_2)



{

  uint *puVar1;

  uint uVar2;

  uint *puVar3;

  int iVar4;

  

  uVar2 = param_2;

  if (param_2 < (uint)param_1[2]) {

    return 0;

  }

  if ((param_1[1] & 0x7fffffffU) < param_2) {

    if (param_2 != 0) {

      puVar3 = (uint *)thunk_FUN_005df0f5(param_2 * 0x1c + 4);

      if (puVar3 != (uint *)0x0) {

        puVar1 = puVar3 + 1;

        *puVar3 = param_2;

        FUN_00401000(puVar1,0x1c,param_2,FUN_00407b10);

        if (puVar1 != (uint *)0x0) {

          if (*param_1 != 0) {

            param_2 = param_1[2];

            if (-1 < (int)(param_2 + -1)) {

              iVar4 = (param_2 + -1) * 0x1c;

              do {

                FUN_00407750(*param_1 + iVar4);

                iVar4 = iVar4 + -0x1c;

                param_2 = param_2 + -1;

              } while (param_2 != 0);

            }

            if (((param_1[1] & 0x80000000U) == 0x80000000) && (*param_1 != 0)) {

              FUN_00407d80(3);

            }

          }

          *param_1 = (int)puVar1;

          param_1[1] = uVar2 | 0x80000000;

          return 1;

        }

      }

      return 0;

    }

    FUN_00408120();

  }

  return 1;

}





// --- FUN_00408910 at 0x00408910 (size: 219) ---


undefined1 __thiscall FUN_00408910(int *param_1,uint param_2,char param_3)



{

  LONG *lpAddend;

  int iVar1;

  undefined *puVar2;

  undefined *puVar3;

  char cVar4;

  uint uVar5;

  LONG LVar6;

  

  if ((param_1[1] & 0x7fffffffU) < param_2) {

    uVar5 = param_2;

    if (param_3 == '\0') {

      uVar5 = FUN_004077f0(param_2);

    }

    cVar4 = FUN_004082c0(uVar5);

    if (cVar4 == '\0') {

      return 0;

    }

  }

  else {

    _param_3 = param_2;

    if (param_2 < (uint)param_1[2]) {

      do {

        puVar3 = PTR_DAT_00818344;

        lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

        InterlockedIncrement(lpAddend);

        iVar1 = *param_1;

        puVar2 = *(undefined **)(iVar1 + _param_3 * 4);

        if (puVar2 != puVar3) {

          LVar6 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

          if ((LVar6 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

            (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

          }

          *(undefined **)(iVar1 + _param_3 * 4) = puVar3;

          InterlockedIncrement(lpAddend);

        }

        LVar6 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

        if ((LVar6 == 0) && ((undefined4 *)(puVar3 + -0x14) != (undefined4 *)0x0)) {

          (*(code *)**(undefined4 **)(puVar3 + -0x14))(1);

        }

        _param_3 = _param_3 + 1;

      } while (_param_3 < (uint)param_1[2]);

    }

  }

  param_1[2] = param_2;

  return 1;

}





// --- FUN_004089f0 at 0x004089F0 (size: 100) ---


void __thiscall FUN_004089f0(int *param_1,uint param_2,short param_3)



{

  uint uVar1;

  

  uVar1 = *(uint *)(*param_1 + -4);

  if ((param_2 < uVar1) && (*(short *)(*param_1 + param_2 * 2) != param_3)) {

    uVar1 = uVar1 - 1;

    if (param_2 == uVar1) {

      FUN_00402490(&param_3,1);

      return;

    }

    FUN_00408390();

    *(short *)(*param_1 + param_2 * 2) = param_3;

    if ((param_3 == 0) && (param_2 < uVar1)) {

      *(uint *)(*param_1 + -4) = param_2 + 1;

    }

  }

  return;

}





// --- FUN_00408cb0 at 0x00408CB0 (size: 218) ---


undefined4 __thiscall FUN_00408cb0(int param_1,undefined4 *param_2,int param_3)



{

  int iVar1;

  ushort *puVar2;

  char *pcVar3;

  undefined4 uVar4;

  LONG LVar5;

  ushort *puVar6;

  undefined4 *puVar7;

  undefined4 *puVar8;

  

  puVar2 = (ushort *)*param_2;

  iVar1 = *(int *)(puVar2 + -2);

  puVar6 = puVar2 + iVar1 + -1;

  if (iVar1 != 0) {

    puVar6 = puVar2;

  }

  if (*puVar6 == 0) {

    return 0;

  }

  if (iVar1 == 0) {

    puVar2 = puVar2 + -1;

  }

  pcVar3 = strchr(*(char **)(param_1 + 8),(uint)*puVar2);

  if (pcVar3 == (char *)0x0) {

    if ((char)param_3 != '\0') {

      return 0;

    }

    if ((*(int *)(*(char **)(param_1 + 8) + -4) != 1) &&

       (pcVar3 = strchr(*(char **)(param_1 + 8),0x20), pcVar3 == (char *)0x0)) {

      return 0;

    }

    puVar7 = &param_3;

    puVar8 = param_2;

    FUN_00402730(&DAT_00795358);

    uVar4 = FUN_004086c0(puVar7,puVar8);

    FUN_00402070(uVar4);

    puVar7 = (undefined4 *)(param_3 + -0x14);

    LVar5 = InterlockedDecrement((LONG *)(param_3 + -0x10));

    if ((LVar5 == 0) && (puVar7 != (undefined4 *)0x0)) {

      (**(code **)*puVar7)(1);

    }

    LVar5 = InterlockedDecrement(param_2 + -4);

    if ((LVar5 == 0) && (param_2 + -5 != (undefined4 *)0x0)) {

      (**(code **)param_2[-5])(1);

    }

  }

  return 1;

}





// --- FUN_00408d90 at 0x00408D90 (size: 173) ---


undefined4 __thiscall FUN_00408d90(int *param_1,uint param_2)



{

  char *pcVar1;

  int iVar2;

  char cVar3;

  LONG LVar4;

  

  pcVar1 = (char *)*param_1;

  if ((*(int *)(pcVar1 + -0x10) == 1) && (param_2 + 1 <= *(uint *)(pcVar1 + -4))) {

    param_2 = param_2 & 0xffffff00;

    iVar2 = *(int *)(pcVar1 + -4);

    if ((iVar2 != 0) && (*pcVar1 != '\0')) {

      if (iVar2 == 1) {

        FUN_00404ef0(&param_2,1);

        return 1;

      }

      FUN_004080c0();

      *(char *)*param_1 = (char)param_2;

      if (((char)param_2 == '\0') && (iVar2 != 1)) {

        *(undefined4 *)(*param_1 + -4) = 1;

      }

    }

    return 1;

  }

  cVar3 = FUN_00401280(param_2);

  if (cVar3 != '\0') {

    LVar4 = InterlockedDecrement((LONG *)(pcVar1 + -0x10));

    if ((LVar4 == 0) && (pcVar1 + -0x14 != (char *)0x0)) {

      (*(code *)**(undefined4 **)(pcVar1 + -0x14))(1);

    }

    *(undefined4 *)(*param_1 + -4) = 1;

    return 1;

  }

  return 0;

}





// --- FUN_00408e40 at 0x00408E40 (size: 120) ---


undefined1 __thiscall FUN_00408e40(int *param_1,int *param_2)



{

  int *piVar1;

  int iVar2;

  char cVar3;

  undefined4 uVar4;

  LONG LVar5;

  

  if ((param_1[1] & 0x7fffffffU) <= (uint)param_1[2]) {

    uVar4 = FUN_004077f0((param_1[1] & 0x7fffffffU) + 1);

    cVar3 = FUN_00407f10(uVar4);

    if (cVar3 == '\0') {

      return 0;

    }

  }

  piVar1 = (int *)(*param_1 + param_1[2] * 4);

  iVar2 = *piVar1;

  if (iVar2 != *param_2) {

    LVar5 = InterlockedDecrement((LONG *)(iVar2 + -0x10));

    if ((LVar5 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

    }

    iVar2 = *param_2;

    *piVar1 = iVar2;

    InterlockedIncrement((LONG *)(iVar2 + -0x10));

  }

  param_1[2] = param_1[2] + 1;

  return 1;

}





// --- FUN_00408ec0 at 0x00408EC0 (size: 180) ---


undefined4 __thiscall FUN_00408ec0(int *param_1,int param_2)



{

  short *psVar1;

  int iVar2;

  char cVar3;

  LONG LVar4;

  

  psVar1 = (short *)*param_1;

  if ((*(int *)(psVar1 + -8) == 1) && (param_2 + 1U <= *(uint *)(psVar1 + -2))) {

    param_2 = 0;

    iVar2 = *(int *)(psVar1 + -2);

    if ((iVar2 != 0) && (*psVar1 != 0)) {

      if (iVar2 == 1) {

        FUN_00402490(&param_2,1);

        return 1;

      }

      FUN_00408390();

      *(short *)*param_1 = (short)param_2;

      if (((short)param_2 == 0) && (iVar2 != 1)) {

        *(undefined4 *)(*param_1 + -4) = 1;

      }

    }

    return 1;

  }

  cVar3 = FUN_004022d0(param_2);

  if (cVar3 != '\0') {

    LVar4 = InterlockedDecrement((LONG *)(psVar1 + -8));

    if ((LVar4 == 0) && (psVar1 + -10 != (short *)0x0)) {

      (*(code *)**(undefined4 **)(psVar1 + -10))(1);

    }

    *(undefined4 *)(*param_1 + -4) = 1;

    return 1;

  }

  return 0;

}





// --- FUN_00408f80 at 0x00408F80 (size: 65) ---


undefined4 __thiscall FUN_00408f80(int param_1,ushort param_2)



{

  ushort *puVar1;

  

  puVar1 = *(ushort **)(*(int *)(param_1 + 0xe4) + ((uint)param_2 % *(uint *)(param_1 + 0xec)) * 4);

  while( true ) {

    if (puVar1 == (ushort *)0x0) {

      return 0xffffffff;

    }

    if (*puVar1 == param_2) break;

    puVar1 = *(ushort **)(puVar1 + 2);

  }

  if (puVar1 == (ushort *)0x0) {

    return 0xffffffff;

  }

  return *(undefined4 *)(puVar1 + 4);

}





// --- FUN_00408fd0 at 0x00408FD0 (size: 640) ---


int * __thiscall FUN_00408fd0(int *param_1,int *param_2,ushort param_3)



{

  LONG *lpAddend;

  undefined *puVar1;

  LONG LVar2;

  int iVar3;

  ushort *puVar4;

  DWORD DVar5;

  DWORD DVar6;

  int *piVar7;

  int iVar8;

  int *unaff_EDI;

  int *piVar9;

  uint uVar10;

  int iStack_4c;

  undefined1 *puStack_48;

  int *piStack_44;

  

  puVar1 = PTR_DAT_00818344;

  lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

  InterlockedIncrement(lpAddend);

  if (*(int *)(*param_1 + -4) == 1) {

    *param_2 = (int)puVar1;

    InterlockedIncrement(lpAddend);

    LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(puVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar1 + -0x14))();

    }

    return param_2;

  }

  piVar9 = (int *)(uint)param_3;

  piVar7 = (int *)&DAT_007953a4;

  if (piVar9 < (int *)0xcec9) {

    if (piVar9 != (int *)0xcec8) {

      switch(piVar9) {

      case (int *)0xc42c:

      case (int *)0xc42d:

      case (int *)0xc42e:

      case (int *)0xc431:

      case (int *)0xc433:

      case (int *)0xc435:

        break;

      default:

        goto switchD_0040905f_caseD_c42f;

      }

    }

  }

  else if (piVar9 < (int *)0xdeb4) {

    if ((piVar9 < (int *)0xdeaa) && (piVar9 != (int *)0xd698)) goto switchD_0040905f_caseD_c42f;

  }

  else if ((piVar9 < (int *)0xfde8) || ((int *)0xfde9 < piVar9)) goto switchD_0040905f_caseD_c42f;

  piVar7 = (int *)0x0;

switchD_0040905f_caseD_c42f:

  iVar3 = (*(code *)PTR_FUN_00837398)();

  if (iVar3 == 0) {

    iVar3 = *(int *)(*piVar7 + -4) + -1;

    piStack_44 = (int *)0x4090d4;

    FUN_00408d90();

    if (0 < iVar3) {

      uVar10 = 0;

      do {

        puVar1 = PTR_DAT_00818344;

        iVar8 = *piVar7;

        if (uVar10 < *(uint *)(iVar8 + -4)) {

          puVar4 = (ushort *)(iVar8 + uVar10 * 2);

        }

        else {

          puVar4 = (ushort *)(iVar8 + -2 + *(uint *)(iVar8 + -4) * 2);

        }

        if (*puVar4 < 0x80) {

          piStack_44 = (int *)&stack0xffffffe8;

          puStack_48 = (undefined1 *)0x409175;

          FUN_00404ef0();

        }

        else {

          piStack_44 = (int *)0x409112;

          InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

          puStack_48 = &stack0xffffffe8;

          piStack_44 = (int *)0x79539c;

          iStack_4c = 0x409125;

          FUN_00402710();

          if (*(int *)(puVar1 + -4) != 1) {

            piStack_44 = (int *)puVar1;

            puStack_48 = (undefined1 *)0x409142;

            FUN_00404ef0();

          }

          piStack_44 = (int *)0x40914f;

          LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

          if ((LVar2 == 0) && ((undefined4 *)(puVar1 + -0x14) != (undefined4 *)0x0)) {

            piStack_44 = (int *)0x40915f;

            (*(code *)**(undefined4 **)(puVar1 + -0x14))();

          }

        }

        uVar10 = uVar10 + 1;

      } while ((int)uVar10 < iVar3);

    }

    *unaff_EDI = 0;

    piStack_44 = (int *)0x409194;

    InterlockedIncrement((LONG *)0xfffffff0);

    piStack_44 = (int *)0x4091a1;

    LVar2 = InterlockedDecrement((LONG *)0xfffffff0);

    piVar9 = unaff_EDI;

    if (LVar2 == 0) {

      piStack_44 = (int *)0x4091b9;

      (*(code *)*puRamffffffec)();

      return unaff_EDI;

    }

  }

  else {

    piStack_44 = (int *)0x4091cf;

    FUN_00401280();

    iVar8 = 0;

    iStack_4c = 0;

    puStack_48 = (undefined1 *)iVar3;

    piStack_44 = piVar7;

    iVar3 = (*(code *)PTR_FUN_00837398)(piVar9,0,*piVar7,*(undefined4 *)(*piVar7 + -4));

    if (iVar3 == 0) {

      DVar5 = GetLastError();

      DVar6 = GetLastError();

      FUN_00402710(&iStack_4c,"Failed conversion to codepage %hu! GetLastError %d (0x%08x)\n",piVar9

                   ,DVar6,DVar5);

      iVar8 = iStack_4c;

      iVar3 = iRamfffffffc;

    }

    iRamfffffffc = iVar3;

    *piVar9 = iVar8;

    InterlockedIncrement((LONG *)(iVar8 + -0x10));

    LVar2 = InterlockedDecrement((LONG *)(iVar8 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar8 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar8 + -0x14))(1);

    }

  }

  return piVar9;

}





// --- FUN_00409270 at 0x00409270 (size: 80) ---


void __thiscall FUN_00409270(int param_1,undefined4 param_2)



{

  char cVar1;

  uint uVar2;

  undefined4 uVar3;

  

  uVar2 = *(uint *)(param_1 + 4) & 0x7fffffff;

  if (uVar2 <= *(uint *)(param_1 + 8)) {

    uVar3 = FUN_004077f0(uVar2 + 1);

    cVar1 = FUN_00408830(uVar3);

    if (cVar1 == '\0') {

      return;

    }

  }

  FUN_00407750(param_2);

  *(int *)(param_1 + 8) = *(int *)(param_1 + 8) + 1;

  return;

}





// --- FUN_004092c0 at 0x004092C0 (size: 100) ---


undefined4 FUN_004092c0(int *param_1)



{

  int iVar1;

  LONG LVar2;

  undefined4 uVar3;

  undefined1 local_c [8];

  int local_4;

  

  iVar1 = *param_1;

  uVar3 = 0xffffffff;

  param_1 = (int *)iVar1;

  InterlockedIncrement((LONG *)(iVar1 + -0x10));

  FUN_00408610(local_c,&param_1);

  if (local_4 != 0) {

    uVar3 = *(undefined4 *)(local_4 + 8);

  }

  LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

  if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

  }

  return uVar3;

}





// --- FUN_00409330 at 0x00409330 (size: 374) ---


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

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

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

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

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

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

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



void __thiscall FUN_00409330(int *param_1,int *param_2)



{

  int *piVar1;

  int iVar2;

  int *piVar3;

  char cVar4;

  undefined4 extraout_ECX;

  uint uVar5;

  uint _NumOfElements;

  undefined4 uVar6;

  int iVar7;

  int iVar8;

  int local_28;

  uint local_14;

  undefined1 local_10;

  undefined1 local_f;

  

  piVar3 = param_2;

  local_14 = 0;

  FUN_00408220(param_2[2]);

  piVar1 = param_2 + 2;

  param_2 = (int *)0x0;

  _NumOfElements = 0;

  if (*piVar1 != 0) {

    local_28 = 0;

    do {

      iVar8 = *piVar3;

      cVar4 = FUN_00408220(8);

      if (cVar4 != '\0') {

        *(int *)(local_14 * 4) = iVar8 + local_28;

        local_14 = local_14 + 1;

      }

      param_2 = (int *)((int)param_2 + 1);

      local_28 = local_28 + 0x1c;

      _NumOfElements = local_14;

    } while (param_2 < (uint)piVar3[2]);

  }

  uVar5 = 0;

  qsort((void *)0x0,_NumOfElements,4,(_PtFuncCompare *)&LAB_004075e0);

  if (_NumOfElements != 0) {

    do {

      local_10 = *(undefined1 *)(*(int *)(uVar5 * 4) + 4);

      iVar8 = *(int *)(*(int *)(uVar5 * 4) + 0xc);

      local_f = 0;

      InterlockedIncrement((LONG *)(iVar8 + -0x10));

      iVar7 = *(int *)(*(int *)(uVar5 * 4) + 8);

      InterlockedIncrement((LONG *)(iVar7 + -0x10));

      iVar2 = *param_1;

      uVar6 = extraout_ECX;

      FUN_00401340(&local_10);

      (**(code **)(iVar2 + 0x2c))(uVar6,iVar7,iVar8);

      uVar5 = uVar5 + 1;

    } while (uVar5 < _NumOfElements);

  }

  return;

}





// --- FUN_004094b0 at 0x004094B0 (size: 151) ---


undefined4 * __thiscall FUN_004094b0(undefined4 *param_1,uint param_2)



{

  undefined *puVar1;

  uint *puVar2;

  undefined4 uVar3;

  uint uVar4;

  int iVar5;

  undefined4 *puVar6;

  uint local_4;

  

  local_4 = param_2;

  param_2 = param_2 & 0xffffff00;

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  *param_1 = &PTR_FUN_00795324;

  puVar1 = PTR_DAT_00818558;

  puVar2 = (uint *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,param_2,0);

  if (puVar2 == (uint *)puVar1) {

    puVar2 = puVar2 + -1;

  }

  uVar4 = *puVar2;

  param_1[0x1a] = uVar4;

  if (uVar4 < 0x18) {

    param_1[0x18] = param_1 + 1;

  }

  else {

    uVar3 = thunk_FUN_005df0f5(uVar4 * 4);

    param_1[0x18] = uVar3;

  }

  param_1[0x19] = (undefined4 *)param_1[0x18] + param_1[0x1a];

  puVar6 = (undefined4 *)param_1[0x18];

  for (uVar4 = param_1[0x1a] & 0x3fffffff; uVar4 != 0; uVar4 = uVar4 - 1) {

    *puVar6 = 0;

    puVar6 = puVar6 + 1;

  }

  for (iVar5 = 0; iVar5 != 0; iVar5 = iVar5 + -1) {

    *(undefined1 *)puVar6 = 0;

    puVar6 = (undefined4 *)((int)puVar6 + 1);

  }

  return param_1;

}





// --- FUN_00409550 at 0x00409550 (size: 151) ---


undefined4 * __thiscall FUN_00409550(undefined4 *param_1,uint param_2)



{

  undefined *puVar1;

  uint *puVar2;

  undefined4 uVar3;

  uint uVar4;

  int iVar5;

  undefined4 *puVar6;

  uint local_4;

  

  local_4 = param_2;

  param_2 = param_2 & 0xffffff00;

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  *param_1 = &PTR_FUN_00795328;

  puVar1 = PTR_DAT_00818558;

  puVar2 = (uint *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,param_2,0);

  if (puVar2 == (uint *)puVar1) {

    puVar2 = puVar2 + -1;

  }

  uVar4 = *puVar2;

  param_1[0x1a] = uVar4;

  if (uVar4 < 0x18) {

    param_1[0x18] = param_1 + 1;

  }

  else {

    uVar3 = thunk_FUN_005df0f5(uVar4 * 4);

    param_1[0x18] = uVar3;

  }

  param_1[0x19] = (undefined4 *)param_1[0x18] + param_1[0x1a];

  puVar6 = (undefined4 *)param_1[0x18];

  for (uVar4 = param_1[0x1a] & 0x3fffffff; uVar4 != 0; uVar4 = uVar4 - 1) {

    *puVar6 = 0;

    puVar6 = puVar6 + 1;

  }

  for (iVar5 = 0; iVar5 != 0; iVar5 = iVar5 + -1) {

    *(undefined1 *)puVar6 = 0;

    puVar6 = (undefined4 *)((int)puVar6 + 1);

  }

  return param_1;

}





// --- FUN_004095f0 at 0x004095F0 (size: 82) ---


void __fastcall FUN_004095f0(int param_1)



{

  undefined *puVar1;

  undefined4 *puVar2;

  uint local_8;

  undefined4 local_4;

  

  puVar1 = PTR_DAT_00818558;

  local_4 = *(undefined4 *)(param_1 + 0x68);

  local_8 = local_8 & 0xffffff00;

  puVar2 = (undefined4 *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,local_8,0);

  if ((puVar2 != (undefined4 *)puVar1) || (puVar2 = puVar2 + -1, puVar2 != (undefined4 *)puVar1)) {

    puVar2 = puVar2 + 1;

  }

  FUN_00409c10(*puVar2);

  return;

}





// --- FUN_00409650 at 0x00409650 (size: 82) ---


void __fastcall FUN_00409650(int param_1)



{

  undefined *puVar1;

  undefined4 *puVar2;

  uint local_8;

  undefined4 local_4;

  

  puVar1 = PTR_DAT_00818558;

  local_4 = *(undefined4 *)(param_1 + 0x68);

  local_8 = local_8 & 0xffffff00;

  puVar2 = (undefined4 *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,local_8,0);

  if ((puVar2 != (undefined4 *)puVar1) || (puVar2 = puVar2 + -1, puVar2 != (undefined4 *)puVar1)) {

    puVar2 = puVar2 + 1;

  }

  FUN_00409d20(*puVar2);

  return;

}





// --- FUN_004096b0 at 0x004096B0 (size: 207) ---


bool FUN_004096b0(char *param_1,undefined4 param_2,int *param_3)



{

  bool bVar1;

  bool bVar2;

  char cVar3;

  char *pcVar4;

  undefined4 uVar5;

  char *pcVar6;

  

  if (param_1 == (char *)0x0) {

    return false;

  }

  pcVar4 = param_1;

  do {

    cVar3 = *pcVar4;

    pcVar4 = pcVar4 + 1;

  } while (cVar3 != '\0');

  FUN_004074b0(pcVar4 + (1 - (int)(param_1 + 1)),1);

  pcVar4 = (char *)FUN_00406d80();

  bVar1 = false;

  param_1 = param_1 + -1;

  bVar2 = false;

  pcVar6 = pcVar4;

  do {

    cVar3 = param_1[1];

    param_1 = param_1 + 1;

    if ((cVar3 == '\0') || ((cVar3 == ' ' && (!bVar2)))) {

      if (bVar1) {

        *pcVar6 = '\0';

        pcVar6 = pcVar6 + 1;

        if ((uint)param_3[2] < (param_3[1] & 0x7fffffffU)) {

LAB_0040975f:

          *(char **)(*param_3 + param_3[2] * 4) = pcVar4;

          param_3[2] = param_3[2] + 1;

        }

        else {

          uVar5 = FUN_004077f0((param_3[1] & 0x7fffffffU) + 1);

          cVar3 = FUN_00408220(uVar5);

          if (cVar3 != '\0') goto LAB_0040975f;

        }

        bVar1 = false;

      }

    }

    else if (cVar3 == '\"') {

      bVar2 = !bVar2;

    }

    else {

      if (!bVar1) {

        bVar1 = true;

        pcVar4 = pcVar6;

      }

      *pcVar6 = cVar3;

      pcVar6 = pcVar6 + 1;

    }

    if (*param_1 == '\0') {

      return !bVar2;

    }

  } while( true );

}





// --- FUN_00409780 at 0x00409780 (size: 220) ---


bool FUN_00409780(wchar_t *param_1,undefined4 param_2,int *param_3)



{

  wchar_t wVar1;

  bool bVar2;

  bool bVar3;

  char cVar4;

  size_t sVar5;

  wchar_t *pwVar6;

  undefined4 uVar7;

  wchar_t *pwVar8;

  

  if (param_1 == (wchar_t *)0x0) {

    return false;

  }

  sVar5 = wcslen(param_1);

  FUN_004074b0(sVar5 * 2 + 2,1);

  pwVar6 = (wchar_t *)FUN_00406d80();

  bVar2 = false;

  param_1 = param_1 + -1;

  bVar3 = false;

  pwVar8 = pwVar6;

  do {

    wVar1 = param_1[1];

    param_1 = param_1 + 1;

    if ((wVar1 == L'\0') || ((wVar1 == L' ' && (!bVar3)))) {

      if (bVar2) {

        *pwVar8 = L'\0';

        pwVar8 = pwVar8 + 1;

        if ((uint)param_3[2] < (param_3[1] & 0x7fffffffU)) {

LAB_00409837:

          *(wchar_t **)(*param_3 + param_3[2] * 4) = pwVar6;

          param_3[2] = param_3[2] + 1;

        }

        else {

          uVar7 = FUN_004077f0((param_3[1] & 0x7fffffffU) + 1);

          cVar4 = FUN_00408220(uVar7);

          if (cVar4 != '\0') goto LAB_00409837;

        }

        bVar2 = false;

      }

    }

    else if (wVar1 == L'\"') {

      bVar3 = !bVar3;

    }

    else {

      if (!bVar2) {

        bVar2 = true;

        pwVar6 = pwVar8;

      }

      *pwVar8 = wVar1;

      pwVar8 = pwVar8 + 1;

    }

    if (*param_1 == L'\0') {

      return !bVar3;

    }

  } while( true );

}





// --- FUN_00409860 at 0x00409860 (size: 144) ---


undefined1 __thiscall FUN_00409860(int *param_1,uint *param_2,uint *param_3)



{

  uint *puVar1;

  int iVar2;

  undefined1 uVar3;

  undefined4 uVar4;

  LONG LVar5;

  

  puVar1 = param_2;

  uVar3 = 1;

  if (((*param_2 & 0xff) == 0x32) || ((*param_2 & 0xff) != 0x3a)) {

    iVar2 = *param_1;

    uVar4 = FUN_00408fd0(&param_2,0);

    uVar3 = (**(code **)(iVar2 + 0x3c))(puVar1,uVar4);

    puVar1 = param_2;

  }

  else {

    if (param_2[4] == 0) {

      return 1;

    }

    puVar1 = (uint *)*param_3;

    param_3 = puVar1;

    InterlockedIncrement((LONG *)(puVar1 + -4));

    FUN_00402070(&param_3);

  }

  LVar5 = InterlockedDecrement((LONG *)(puVar1 + -4));

  if ((LVar5 == 0) && (puVar1 + -5 != (uint *)0x0)) {

    (**(code **)puVar1[-5])(1);

  }

  return uVar3;

}





// --- thunk_FUN_004096b0 at 0x004098F0 (size: 5) ---


bool thunk_FUN_004096b0(char *param_1,undefined4 param_2,int *param_3)



{

  bool bVar1;

  bool bVar2;

  char cVar3;

  char *pcVar4;

  undefined4 uVar5;

  char *pcVar6;

  

  if (param_1 == (char *)0x0) {

    return false;

  }

  pcVar4 = param_1;

  do {

    cVar3 = *pcVar4;

    pcVar4 = pcVar4 + 1;

  } while (cVar3 != '\0');

  FUN_004074b0(pcVar4 + (1 - (int)(param_1 + 1)),1);

  pcVar4 = (char *)FUN_00406d80();

  bVar1 = false;

  param_1 = param_1 + -1;

  bVar2 = false;

  pcVar6 = pcVar4;

  do {

    cVar3 = param_1[1];

    param_1 = param_1 + 1;

    if ((cVar3 == '\0') || ((cVar3 == ' ' && (!bVar2)))) {

      if (bVar1) {

        *pcVar6 = '\0';

        pcVar6 = pcVar6 + 1;

        if ((uint)param_3[2] < (param_3[1] & 0x7fffffffU)) {

LAB_0040975f:

          *(char **)(*param_3 + param_3[2] * 4) = pcVar4;

          param_3[2] = param_3[2] + 1;

        }

        else {

          uVar5 = FUN_004077f0((param_3[1] & 0x7fffffffU) + 1);

          cVar3 = FUN_00408220(uVar5);

          if (cVar3 != '\0') goto LAB_0040975f;

        }

        bVar1 = false;

      }

    }

    else if (cVar3 == '\"') {

      bVar2 = !bVar2;

    }

    else {

      if (!bVar1) {

        bVar1 = true;

        pcVar4 = pcVar6;

      }

      *pcVar6 = cVar3;

      pcVar6 = pcVar6 + 1;

    }

    if (*param_1 == '\0') {

      return !bVar2;

    }

  } while( true );

}





// --- FUN_00409900 at 0x00409900 (size: 245) ---


undefined1 __thiscall FUN_00409900(int *param_1,int param_2,undefined4 param_3)



{

  int iVar1;

  void *pvVar2;

  char cVar3;

  undefined1 uVar4;

  LONG LVar5;

  void *unaff_EBX;

  uint unaff_ESI;

  int unaff_retaddr;

  void *local_18;

  undefined4 local_14;

  undefined4 local_10;

  undefined1 local_c [12];

  

  iVar1 = param_2;

  if (param_2 != 0) {

    FUN_00406d60();

    local_18 = (void *)0x0;

    local_14 = 0;

    local_10 = 0;

    cVar3 = FUN_004096b0(iVar1,local_c,&local_18);

    pvVar2 = local_18;

    if (cVar3 != '\0') {

      uVar4 = (**(code **)(*param_1 + 0x10))(local_18,local_10,param_3);

      if ((unaff_ESI & 0x80000000) == 0x80000000) {

        operator_delete__(pvVar2);

      }

      FUN_00406f90();

      return uVar4;

    }

    FUN_00401340("Unmatched quote");

    (**(code **)(*param_1 + 0x20))(&param_2);

    LVar5 = InterlockedDecrement((LONG *)(unaff_retaddr + -0x10));

    if ((LVar5 == 0) && ((undefined4 *)(unaff_retaddr + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(unaff_retaddr + -0x14))(1);

    }

    if (((uint)local_18 & 0x80000000) == 0x80000000) {

      operator_delete__(unaff_EBX);

    }

    FUN_00406f90();

  }

  return 0;

}





// --- FUN_00409a00 at 0x00409A00 (size: 245) ---


undefined1 __thiscall FUN_00409a00(int *param_1,int param_2,undefined4 param_3)



{

  int iVar1;

  void *pvVar2;

  char cVar3;

  undefined1 uVar4;

  LONG LVar5;

  void *unaff_EBX;

  uint unaff_ESI;

  int unaff_retaddr;

  void *local_18;

  undefined4 local_14;

  undefined4 local_10;

  undefined1 local_c [12];

  

  iVar1 = param_2;

  if (param_2 != 0) {

    FUN_00406d60();

    local_18 = (void *)0x0;

    local_14 = 0;

    local_10 = 0;

    cVar3 = FUN_00409780(iVar1,local_c,&local_18);

    pvVar2 = local_18;

    if (cVar3 != '\0') {

      uVar4 = (**(code **)(*param_1 + 0xc))(local_18,local_10,param_3);

      if ((unaff_ESI & 0x80000000) == 0x80000000) {

        operator_delete__(pvVar2);

      }

      FUN_00406f90();

      return uVar4;

    }

    FUN_00401340("Unmatched quote");

    (**(code **)(*param_1 + 0x20))(&param_2);

    LVar5 = InterlockedDecrement((LONG *)(unaff_retaddr + -0x10));

    if ((LVar5 == 0) && ((undefined4 *)(unaff_retaddr + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(unaff_retaddr + -0x14))(1);

    }

    if (((uint)local_18 & 0x80000000) == 0x80000000) {

      operator_delete__(unaff_EBX);

    }

    FUN_00406f90();

  }

  return 0;

}





// --- FUN_00409b00 at 0x00409B00 (size: 186) ---


undefined1 __thiscall FUN_00409b00(int *param_1,int param_2,int param_3,undefined4 param_4)



{

  undefined1 uVar1;

  undefined4 uVar2;

  LONG LVar3;

  int unaff_EBX;

  int iVar4;

  undefined4 local_c;

  undefined4 local_8;

  undefined4 local_4;

  

  iVar4 = 0;

  local_c = 0;

  local_8 = 0;

  local_4 = 0;

  FUN_00407f10(param_3);

  if (0 < param_3) {

    do {

      uVar2 = FUN_00404a40(0,*(undefined4 *)(param_2 + iVar4 * 4));

      FUN_00408e40(uVar2);

      LVar3 = InterlockedDecrement((LONG *)(param_2 + -0x10));

      if ((LVar3 == 0) && ((undefined4 *)(param_2 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(param_2 + -0x14))(1);

      }

      iVar4 = iVar4 + 1;

    } while (iVar4 < param_3);

  }

  uVar1 = (**(code **)(*param_1 + 4))(&local_c,param_4);

  if ((((uint)param_1 & 0x80000000) == 0x80000000) && (unaff_EBX != 0)) {

    FUN_00407920(3);

  }

  return uVar1;

}





// --- FUN_00409bc0 at 0x00409BC0 (size: 78) ---


void __thiscall FUN_00409bc0(int param_1,int param_2)



{

  uint uVar1;

  int iVar2;

  uint uVar3;

  

  if (*(int *)(param_1 + 0x68) * 2 < *(int *)(param_1 + 0x6c) + 1) {

    FUN_004095f0();

  }

  uVar1 = *(uint *)(param_1 + 0x68);

  uVar3 = FUN_00407680();

  uVar3 = uVar3 % uVar1;

  iVar2 = *(int *)(param_1 + 0x60);

  *(undefined4 *)(param_2 + 4) = *(undefined4 *)(iVar2 + uVar3 * 4);

  *(int *)(iVar2 + uVar3 * 4) = param_2;

  uVar1 = iVar2 + uVar3 * 4;

  if (uVar1 < *(uint *)(param_1 + 100)) {

    *(uint *)(param_1 + 100) = uVar1;

  }

  *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + 1;

  return;

}





// --- FUN_00409c10 at 0x00409C10 (size: 254) ---


undefined4 __thiscall FUN_00409c10(int param_1,int param_2)



{

  uint uVar1;

  int iVar2;

  int iVar3;

  uint uVar4;

  int *piVar5;

  int iVar6;

  int iVar7;

  

  if (param_2 == *(int *)(param_1 + 0x68)) {

    return 0;

  }

  iVar6 = 0;

  if (*(int *)(param_1 + 0x6c) != 0) {

    iVar7 = 0;

    do {

      piVar5 = *(int **)(param_1 + 100);

      while (piVar5 != (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

        if (**(int **)(param_1 + 100) != 0) {

          piVar5 = *(int **)(param_1 + 100);

          iVar6 = *piVar5;

          goto LAB_00409c5e;

        }

        piVar5 = *(int **)(param_1 + 100) + 1;

        *(int **)(param_1 + 100) = piVar5;

      }

      piVar5 = (int *)0x0;

      iVar6 = 0;

LAB_00409c5e:

      iVar3 = *piVar5;

      if (iVar3 == iVar6) {

LAB_00409c71:

        *piVar5 = *(int *)(iVar3 + 4);

      }

      else {

        do {

          iVar2 = iVar3;

          iVar3 = *(int *)(iVar2 + 4);

        } while (iVar3 != iVar6);

        if (iVar2 == 0) goto LAB_00409c71;

        *(undefined4 *)(iVar2 + 4) = *(undefined4 *)(iVar3 + 4);

      }

      *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

      *(int *)(iVar6 + 4) = iVar7;

      iVar7 = iVar6;

    } while (*(int *)(param_1 + 0x6c) != 0);

  }

  if (*(void **)(param_1 + 0x60) != (void *)(param_1 + 4)) {

    operator_delete__(*(void **)(param_1 + 0x60));

  }

  *(undefined4 *)(param_1 + 0x60) = 0;

  *(undefined4 *)(param_1 + 100) = 0;

  *(undefined4 *)(param_1 + 0x68) = 0;

  *(undefined4 *)(param_1 + 0x6c) = 0;

  FUN_0065ec90(param_2);

  while (iVar6 != 0) {

    iVar7 = *(int *)(iVar6 + 4);

    if (*(int *)(param_1 + 0x68) * 2 < *(int *)(param_1 + 0x6c) + 1) {

      FUN_004095f0();

    }

    uVar1 = *(uint *)(param_1 + 0x68);

    uVar4 = FUN_00407680();

    uVar4 = uVar4 % uVar1;

    iVar3 = *(int *)(param_1 + 0x60);

    *(undefined4 *)(iVar6 + 4) = *(undefined4 *)(iVar3 + uVar4 * 4);

    *(int *)(iVar3 + uVar4 * 4) = iVar6;

    uVar1 = iVar3 + uVar4 * 4;

    if (uVar1 < *(uint *)(param_1 + 100)) {

      *(uint *)(param_1 + 100) = uVar1;

    }

    *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + 1;

    iVar6 = iVar7;

  }

  return 1;

}





// --- FUN_00409d20 at 0x00409D20 (size: 248) ---


undefined4 __thiscall FUN_00409d20(int param_1,int param_2)



{

  int iVar1;

  ushort *puVar2;

  int *piVar3;

  ushort *puVar4;

  ushort *puVar5;

  ushort *puVar6;

  uint uVar7;

  undefined4 *puVar8;

  

  if (param_2 == *(int *)(param_1 + 0x68)) {

    return 0;

  }

  iVar1 = *(int *)(param_1 + 0x6c);

  puVar2 = (ushort *)0x0;

  do {

    if (iVar1 == 0) {

      if (*(void **)(param_1 + 0x60) != (void *)(param_1 + 4)) {

        operator_delete__(*(void **)(param_1 + 0x60));

      }

      *(undefined4 *)(param_1 + 0x60) = 0;

      *(undefined4 *)(param_1 + 100) = 0;

      *(undefined4 *)(param_1 + 0x68) = 0;

      *(undefined4 *)(param_1 + 0x6c) = 0;

      FUN_0065ec90(param_2);

      while (puVar2 != (ushort *)0x0) {

        puVar6 = *(ushort **)(puVar2 + 2);

        if (*(int *)(param_1 + 0x68) * 2 < *(int *)(param_1 + 0x6c) + 1) {

          FUN_00409650();

        }

        uVar7 = (uint)*puVar2 % *(uint *)(param_1 + 0x68);

        iVar1 = *(int *)(param_1 + 0x60);

        *(undefined4 *)(puVar2 + 2) = *(undefined4 *)(iVar1 + uVar7 * 4);

        *(ushort **)(iVar1 + uVar7 * 4) = puVar2;

        uVar7 = iVar1 + uVar7 * 4;

        if (uVar7 < *(uint *)(param_1 + 100)) {

          *(uint *)(param_1 + 100) = uVar7;

        }

        *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + 1;

        puVar2 = puVar6;

      }

      return 1;

    }

    piVar3 = *(int **)(param_1 + 100);

    while (piVar3 != (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

      if (**(int **)(param_1 + 100) != 0) {

        puVar8 = *(undefined4 **)(param_1 + 100);

        puVar6 = (ushort *)*puVar8;

        goto LAB_00409d6f;

      }

      piVar3 = *(int **)(param_1 + 100) + 1;

      *(int **)(param_1 + 100) = piVar3;

    }

    puVar8 = (undefined4 *)0x0;

    puVar6 = (ushort *)0x0;

LAB_00409d6f:

    puVar5 = (ushort *)*puVar8;

    if (puVar5 == puVar6) {

LAB_00409d83:

      *puVar8 = *(undefined4 *)(puVar5 + 2);

    }

    else {

      do {

        puVar4 = puVar5;

        puVar5 = *(ushort **)(puVar4 + 2);

      } while (puVar5 != puVar6);

      if (puVar4 == (ushort *)0x0) goto LAB_00409d83;

      *(undefined4 *)(puVar4 + 2) = *(undefined4 *)(puVar5 + 2);

    }

    *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

    *(ushort **)(puVar6 + 2) = puVar2;

    iVar1 = *(int *)(param_1 + 0x6c);

    puVar2 = puVar6;

  } while( true );

}





// --- FUN_00409e20 at 0x00409E20 (size: 165) ---


void __fastcall FUN_00409e20(int param_1)



{

  int iVar1;

  int *piVar2;

  int *piVar3;

  LONG LVar4;

  int *piVar5;

  int *piVar6;

  undefined4 *puVar7;

  

  iVar1 = *(int *)(param_1 + 0x6c);

  do {

    if (iVar1 == 0) {

      return;

    }

    piVar5 = *(int **)(param_1 + 100);

    while (piVar5 != (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

      if (**(int **)(param_1 + 100) != 0) {

        piVar5 = *(int **)(param_1 + 100);

        piVar6 = (int *)*piVar5;

        goto LAB_00409e63;

      }

      piVar5 = *(int **)(param_1 + 100) + 1;

      *(int **)(param_1 + 100) = piVar5;

    }

    piVar5 = (int *)0x0;

    piVar6 = (int *)0x0;

LAB_00409e63:

    piVar3 = (int *)*piVar5;

    if (piVar3 == piVar6) {

LAB_00409e7d:

      *piVar5 = piVar3[1];

    }

    else {

      do {

        piVar2 = piVar3;

        piVar3 = (int *)piVar2[1];

      } while (piVar3 != piVar6);

      if (piVar2 == (int *)0x0) goto LAB_00409e7d;

      piVar2[1] = piVar3[1];

    }

    *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

    if (piVar6 != (int *)0x0) {

      puVar7 = (undefined4 *)(*piVar6 + -0x14);

      LVar4 = InterlockedDecrement((LONG *)(*piVar6 + -0x10));

      if ((LVar4 == 0) && (puVar7 != (undefined4 *)0x0)) {

        (**(code **)*puVar7)(1);

      }

      operator_delete(piVar6);

    }

    iVar1 = *(int *)(param_1 + 0x6c);

  } while( true );

}





// --- FUN_00409ed0 at 0x00409ED0 (size: 119) ---


uint __thiscall FUN_00409ed0(int param_1,ushort *param_2)



{

  ushort *puVar1;

  int iVar2;

  uint uVar3;

  

  puVar1 = *(ushort **)

            (*(uint *)(param_1 + 0x60) + ((uint)*param_2 % *(uint *)(param_1 + 0x68)) * 4);

  do {

    if (puVar1 == (ushort *)0x0) {

LAB_00409efc:

      if ((int)(*(uint *)(param_1 + 0x68) * 2) < *(int *)(param_1 + 0x6c) + 1) {

        FUN_00409650();

      }

      uVar3 = (uint)*param_2 % *(uint *)(param_1 + 0x68);

      iVar2 = *(int *)(param_1 + 0x60);

      *(undefined4 *)(param_2 + 2) = *(undefined4 *)(iVar2 + uVar3 * 4);

      *(ushort **)(iVar2 + uVar3 * 4) = param_2;

      uVar3 = iVar2 + uVar3 * 4;

      if (uVar3 < *(uint *)(param_1 + 100)) {

        *(uint *)(param_1 + 100) = uVar3;

      }

      *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + 1;

      return CONCAT31((int3)(uVar3 >> 8),1);

    }

    if (*puVar1 == *param_2) {

      if (puVar1 != (ushort *)0x0) {

        return *(uint *)(param_1 + 0x60) & 0xffffff00;

      }

      goto LAB_00409efc;

    }

    puVar1 = *(ushort **)(puVar1 + 2);

  } while( true );

}





// --- FUN_00409f50 at 0x00409F50 (size: 121) ---


void __fastcall FUN_00409f50(int param_1)



{

  int iVar1;

  void *pvVar2;

  void *pvVar3;

  void *pvVar4;

  int *piVar5;

  

  iVar1 = *(int *)(param_1 + 0x6c);

  do {

    if (iVar1 == 0) {

      return;

    }

    piVar5 = *(int **)(param_1 + 100);

    while (piVar5 != (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

      if (**(int **)(param_1 + 100) != 0) {

        piVar5 = *(int **)(param_1 + 100);

        pvVar4 = (void *)*piVar5;

        goto LAB_00409f8f;

      }

      piVar5 = *(int **)(param_1 + 100) + 1;

      *(int **)(param_1 + 100) = piVar5;

    }

    piVar5 = (int *)0x0;

    pvVar4 = (void *)0x0;

LAB_00409f8f:

    pvVar3 = (void *)*piVar5;

    if (pvVar3 == pvVar4) {

LAB_00409fa2:

      *piVar5 = *(int *)((int)pvVar3 + 4);

    }

    else {

      do {

        pvVar2 = pvVar3;

        pvVar3 = *(void **)((int)pvVar2 + 4);

      } while (pvVar3 != pvVar4);

      if (pvVar2 == (void *)0x0) goto LAB_00409fa2;

      *(undefined4 *)((int)pvVar2 + 4) = *(undefined4 *)((int)pvVar3 + 4);

    }

    *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

    if (pvVar4 != (void *)0x0) {

      operator_delete(pvVar4);

    }

    iVar1 = *(int *)(param_1 + 0x6c);

  } while( true );

}





// --- FUN_00409fd0 at 0x00409FD0 (size: 156) ---


undefined4 FUN_00409fd0(int *param_1,int *param_2)



{

  int iVar1;

  int *piVar2;

  LONG LVar3;

  undefined4 *puVar4;

  undefined1 local_c [8];

  int local_4;

  

  piVar2 = (int *)FUN_005df0f5(0xc);

  if (piVar2 == (int *)0x0) {

    piVar2 = (int *)0x0;

  }

  else {

    iVar1 = *param_1;

    *piVar2 = iVar1;

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

    piVar2[1] = 0;

    piVar2[2] = *param_2;

  }

  FUN_00408610(local_c,piVar2);

  if (local_4 == 0) {

    FUN_00409bc0(piVar2);

    return 1;

  }

  if (piVar2 != (int *)0x0) {

    puVar4 = (undefined4 *)(*piVar2 + -0x14);

    LVar3 = InterlockedDecrement((LONG *)(*piVar2 + -0x10));

    if ((LVar3 == 0) && (puVar4 != (undefined4 *)0x0)) {

      (**(code **)*puVar4)(1);

    }

    operator_delete(piVar2);

  }

  return 0;

}





// --- FUN_0040a070 at 0x0040A070 (size: 90) ---


undefined4 FUN_0040a070(undefined2 *param_1,undefined4 *param_2)



{

  char cVar1;

  undefined2 *puVar2;

  

  puVar2 = (undefined2 *)FUN_005df0f5(0xc);

  if (puVar2 == (undefined2 *)0x0) {

    puVar2 = (undefined2 *)0x0;

  }

  else {

    *puVar2 = *param_1;

    *(undefined4 *)(puVar2 + 2) = 0;

    *(undefined4 *)(puVar2 + 4) = *param_2;

  }

  cVar1 = FUN_00409ed0(puVar2);

  if (cVar1 == '\0') {

    if (puVar2 != (undefined2 *)0x0) {

      operator_delete(puVar2);

    }

    return 0;

  }

  return 1;

}





// --- FUN_0040a0d0 at 0x0040A0D0 (size: 288) ---


undefined4 __thiscall FUN_0040a0d0(int param_1,int param_2)



{

  int *piVar1;

  LONG *lpAddend;

  int iVar2;

  int iVar3;

  int iVar4;

  undefined2 extraout_var;

  LONG LVar5;

  undefined4 *puVar6;

  int local_8;

  int local_4;

  

  iVar2 = param_2;

  piVar1 = (int *)(param_2 + 8);

  FUN_00403350(&param_2,0);

  iVar4 = FUN_00408f80((short)*(char *)(iVar2 + 4));

  if (iVar4 < 0) {

    iVar4 = FUN_004092c0(&param_2);

    if (iVar4 < 0) {

      iVar4 = *(int *)(param_1 + 8);

      FUN_00409270(iVar2);

      if (*(char *)(iVar2 + 4) != '\0') {

        local_4 = CONCAT22(extraout_var,(short)*(char *)(iVar2 + 4));

        local_8 = iVar4;

        FUN_0040a070(&local_4,&local_8);

      }

      iVar3 = param_2;

      if ((*(int *)(*piVar1 + -4) != 1) || (*(char *)(iVar2 + 4) == '\0')) {

        lpAddend = (LONG *)(param_2 + -0x10);

        local_4 = param_2;

        param_2 = iVar4;

        InterlockedIncrement(lpAddend);

        FUN_00409fd0(&local_4,&param_2);

        LVar5 = InterlockedDecrement((LONG *)(iVar3 + -0x10));

        if ((LVar5 == 0) && ((undefined4 *)(iVar3 + -0x14) != (undefined4 *)0x0)) {

          (*(code *)**(undefined4 **)(iVar3 + -0x14))(1);

        }

      }

      LVar5 = InterlockedDecrement((LONG *)(iVar3 + -0x10));

      if ((LVar5 == 0) && ((undefined4 *)(iVar3 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(iVar3 + -0x14))(1);

      }

      return 1;

    }

  }

  puVar6 = (undefined4 *)(param_2 + -0x14);

  LVar5 = InterlockedDecrement((LONG *)(param_2 + -0x10));

  if ((LVar5 == 0) && (puVar6 != (undefined4 *)0x0)) {

    (**(code **)*puVar6)(1);

  }

  return 0;

}





// --- FUN_0040a1f0 at 0x0040A1F0 (size: 82) ---


undefined4 * __thiscall FUN_0040a1f0(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_007953b8;

  FUN_00409e20();

  param_1[1] = &PTR_FUN_00795324;

  if ((undefined4 *)param_1[0x19] != param_1 + 2) {

    operator_delete__((undefined4 *)param_1[0x19]);

  }

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  param_1[0x1c] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040a250 at 0x0040A250 (size: 82) ---


undefined4 * __thiscall FUN_0040a250(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_007953bc;

  FUN_00409f50();

  param_1[1] = &PTR_FUN_00795328;

  if ((undefined4 *)param_1[0x19] != param_1 + 2) {

    operator_delete__((undefined4 *)param_1[0x19]);

  }

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  param_1[0x1c] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040a2b0 at 0x0040A2B0 (size: 84) ---


undefined4 * __fastcall FUN_0040a2b0(undefined4 *param_1)



{

  *param_1 = 0;

  param_1[1] = 0;

  param_1[2] = 0;

  param_1[3] = &PTR_FUN_007953b8;

  FUN_004094b0(0);

  param_1[3] = &PTR_FUN_007953b8;

  param_1[0x20] = &PTR_FUN_007953bc;

  FUN_00409550(0);

  param_1[0x20] = &PTR_FUN_007953bc;

  return param_1;

}





// --- FUN_0040a310 at 0x0040A310 (size: 153) ---


void __fastcall FUN_0040a310(int *param_1)



{

  param_1[0x20] = (int)&PTR_FUN_007953bc;

  FUN_00409f50();

  param_1[0x21] = (int)&PTR_FUN_00795328;

  if ((int *)param_1[0x39] != param_1 + 0x22) {

    operator_delete__((int *)param_1[0x39]);

  }

  param_1[0x39] = 0;

  param_1[0x3a] = 0;

  param_1[0x3b] = 0;

  param_1[0x3c] = 0;

  param_1[3] = (int)&PTR_FUN_007953b8;

  FUN_00409e20();

  param_1[4] = (int)&PTR_FUN_00795324;

  if ((int *)param_1[0x1c] != param_1 + 5) {

    operator_delete__((int *)param_1[0x1c]);

  }

  param_1[0x1c] = 0;

  param_1[0x1d] = 0;

  param_1[0x1e] = 0;

  param_1[0x1f] = 0;

  if (((param_1[1] & 0x80000000U) == 0x80000000) && (*param_1 != 0)) {

    FUN_00407d80(3);

  }

  return;

}





// --- FUN_0040a8d0 at 0x0040A8D0 (size: 4) ---


undefined4 __fastcall FUN_0040a8d0(int param_1)



{

  return *(undefined4 *)(param_1 + 0x18);

}





// --- FUN_0040a8e0 at 0x0040A8E0 (size: 10) ---


void __thiscall FUN_0040a8e0(int param_1,undefined4 param_2)



{

  *(undefined4 *)(param_1 + 0x18) = param_2;

  return;

}





// --- FUN_0040a8f0 at 0x0040A8F0 (size: 16) ---


int __fastcall FUN_0040a8f0(int param_1)



{

  int iVar1;

  

  iVar1 = FUN_00406db0();

  return iVar1 - *(int *)(param_1 + 0x18);

}





// --- FUN_0040a900 at 0x0040A900 (size: 26) ---


undefined4 __thiscall FUN_0040a900(int param_1,undefined4 param_2)



{

  FUN_00407140(param_2,0,*(undefined4 *)(param_1 + 0x18));

  return param_2;

}





// --- FUN_0040a920 at 0x0040A920 (size: 24) ---


undefined4 __thiscall FUN_0040a920(int param_1,undefined4 param_2)



{

  FUN_00407390(param_2,*(undefined4 *)(param_1 + 0x18));

  return param_2;

}





// --- FUN_0040a960 at 0x0040A960 (size: 19) ---


undefined4 __fastcall FUN_0040a960(int param_1)



{

  undefined4 uVar1;

  

  if (*(int *)(param_1 + 0x20) == 0) {

    return 0;

  }

                    /* WARNING: Could not recover jumptable at 0x0040a970. Too many branches */

                    /* WARNING: Treating indirect jump as call */

  uVar1 = (**(code **)(**(int **)(param_1 + 0x20) + 0x18))();

  return uVar1;

}





// --- FUN_0040a980 at 0x0040A980 (size: 68) ---


uint FUN_0040a980(char *param_1)



{

  uint uVar1;

  char cVar2;

  

  cVar2 = *param_1;

  uVar1 = 0;

  if (cVar2 != '\0') {

    do {

      uVar1 = uVar1 * 0x10 + (int)cVar2;

      if ((uVar1 & 0xf0000000) != 0) {

        uVar1 = ((uVar1 & 0xf0000000) >> 0x18 ^ uVar1) & 0xfffffff;

      }

      cVar2 = param_1[1];

      param_1 = param_1 + 1;

    } while (cVar2 != '\0');

    if (uVar1 == 0xffffffff) {

      uVar1 = 0xfffffffe;

    }

  }

  return uVar1;

}





// --- FUN_0040a9f0 at 0x0040A9F0 (size: 21) ---


undefined4 __fastcall FUN_0040a9f0(int param_1)



{

  uint uVar1;

  

  uVar1 = *(uint *)(param_1 + 4) & 0x8000;

  return CONCAT31((int3)(uVar1 >> 8),uVar1 == 0x8000);

}





// --- FUN_0040aa10 at 0x0040AA10 (size: 21) ---


void __thiscall FUN_0040aa10(int param_1,char param_2)



{

  if (param_2 != '\0') {

    *(byte *)(param_1 + 5) = *(byte *)(param_1 + 5) | 0x80;

    return;

  }

  *(byte *)(param_1 + 5) = *(byte *)(param_1 + 5) & 0x7f;

  return;

}





// --- FUN_0040aa30 at 0x0040AA30 (size: 21) ---


void __thiscall FUN_0040aa30(int param_1,char param_2)



{

  if (param_2 != '\0') {

    *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 2;

    return;

  }

  *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) & 0xfffffffd;

  return;

}





// --- FUN_0040aa50 at 0x0040AA50 (size: 12) ---


void __fastcall FUN_0040aa50(int param_1)



{

  *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 4;

  *(undefined4 *)(param_1 + 8) = 0x80004005;

  return;

}





// --- FUN_0040aa60 at 0x0040AA60 (size: 15) ---


undefined4 __fastcall FUN_0040aa60(int param_1)



{

  uint uVar1;

  

  uVar1 = *(uint *)(param_1 + 4) & 0xffffff02;

  return CONCAT31((int3)(uVar1 >> 8),(char)uVar1 == '\x02');

}





// --- FUN_0040aa70 at 0x0040AA70 (size: 85) ---


undefined4 __thiscall FUN_0040aa70(int param_1,undefined4 param_2,undefined4 param_3)



{

  char cVar1;

  

  if ((~(byte)(*(uint *)(param_1 + 4) >> 2) & 1) != 0) {

    if (*(int **)(param_1 + 0x20) == (int *)0x0) {

      *(undefined4 *)(param_1 + 8) = 0x80004005;

      *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 4;

      return 0;

    }

    cVar1 = (**(code **)(**(int **)(param_1 + 0x20) + 0x1c))(param_2,param_3);

    if (cVar1 != '\0') {

      return 1;

    }

    *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 4;

    *(undefined4 *)(param_1 + 8) = 0x80004005;

  }

  return 0;

}





// --- FUN_0040aad0 at 0x0040AAD0 (size: 84) ---


undefined4 * __thiscall FUN_0040aad0(int param_1,undefined4 *param_2)



{

  if ((~(byte)(*(uint *)(param_1 + 4) >> 2) & 1) == 0) {

    *param_2 = DAT_008377a8;

    return param_2;

  }

  if (*(int **)(param_1 + 0x20) == (int *)0x0) {

    *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 4;

    *(undefined4 *)(param_1 + 8) = 0x80004005;

    *param_2 = DAT_008377a8;

    return param_2;

  }

  (**(code **)(**(int **)(param_1 + 0x20) + 0x24))(param_2);

  return param_2;

}





// --- FUN_0040ab30 at 0x0040AB30 (size: 89) ---


undefined4 * __thiscall FUN_0040ab30(int param_1,undefined4 *param_2,undefined4 param_3)



{

  if ((~(byte)(*(uint *)(param_1 + 4) >> 2) & 1) == 0) {

    *param_2 = DAT_008377a8;

    return param_2;

  }

  if (*(int **)(param_1 + 0x20) == (int *)0x0) {

    *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 4;

    *(undefined4 *)(param_1 + 8) = 0x80004005;

    *param_2 = DAT_008377a8;

    return param_2;

  }

  (**(code **)(**(int **)(param_1 + 0x20) + 0x20))(param_2,param_3);

  return param_2;

}





// --- FUN_0040ab90 at 0x0040AB90 (size: 19) ---


uint __fastcall FUN_0040ab90(int param_1)



{

  uint in_EAX;

  uint uVar1;

  

  if (*(int *)(param_1 + 0x20) == 0) {

    return in_EAX & 0xffffff00;

  }

                    /* WARNING: Could not recover jumptable at 0x0040aba0. Too many branches */

                    /* WARNING: Treating indirect jump as call */

  uVar1 = (**(code **)(**(int **)(param_1 + 0x20) + 0x2c))();

  return uVar1;

}





// --- FUN_0040abb0 at 0x0040ABB0 (size: 64) ---


undefined4 * __thiscall FUN_0040abb0(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_0079542c;

  if ((undefined4 *)param_1[0x18] != param_1 + 1) {

    operator_delete__((undefined4 *)param_1[0x18]);

  }

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040abf0 at 0x0040ABF0 (size: 55) ---


undefined4 FUN_0040abf0(int param_1)



{

  if ((~(byte)(*(uint *)(param_1 + 4) >> 2) & 1) != 0) {

    FUN_0040aad0(&param_1);

    FUN_0040aa70(0x436f7265,2);

    return 1;

  }

  return 0;

}





// --- FUN_0040ac70 at 0x0040AC70 (size: 113) ---


int __thiscall FUN_0040ac70(int param_1,int param_2,int param_3)



{

  char cVar1;

  int iVar2;

  uint uVar3;

  

  if ((*(uint *)(param_1 + 4) >> 2 & 1) != 0) {

    return 0;

  }

  if ((*(byte *)(param_1 + 4) & 1) != 0) {

    cVar1 = FUN_00406d70();

    if (cVar1 != '\0') {

      FUN_004074b0(param_3 + param_2,1);

      goto LAB_0040acaf;

    }

  }

  uVar3 = FUN_00406db0();

  if (uVar3 < (uint)(param_3 + param_2)) {

    *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 4;

    *(undefined4 *)(param_1 + 8) = 0x80004005;

    return 0;

  }

LAB_0040acaf:

  iVar2 = FUN_00406d80();

  return iVar2 + param_2;

}





// --- FUN_0040acf0 at 0x0040ACF0 (size: 30) ---


void __thiscall FUN_0040acf0(int param_1,int param_2)



{

  int iVar1;

  

  iVar1 = FUN_0040ac70(*(undefined4 *)(param_1 + 0x18),param_2);

  if (iVar1 != 0) {

    *(int *)(param_1 + 0x18) = *(int *)(param_1 + 0x18) + param_2;

  }

  return;

}





// --- FUN_0040ad10 at 0x0040AD10 (size: 128) ---


void __thiscall FUN_0040ad10(int param_1,uint param_2)



{

  int iVar1;

  int iVar2;

  undefined4 *puVar3;

  uint uVar4;

  uint uVar5;

  

  if ((*(byte *)(param_1 + 4) & 2) != 0) {

    if ((param_2 & 3) == 0) {

      uVar5 = 4;

    }

    else {

      if ((param_2 & 3) != 2) {

        return;

      }

      uVar5 = 2;

    }

    iVar1 = *(int *)(param_1 + 0x18);

    iVar2 = FUN_00406d80();

    uVar4 = (uint)(iVar2 + iVar1) % uVar5;

    if (uVar4 != 0) {

      uVar5 = uVar5 - uVar4;

      puVar3 = (undefined4 *)FUN_0040ac70(iVar1,uVar5);

      if (puVar3 == (undefined4 *)0x0) {

        *(uint *)(param_1 + 4) = *(uint *)(param_1 + 4) | 4;

        *(undefined4 *)(param_1 + 8) = 0x80004005;

        return;

      }

      *(int *)(param_1 + 0x18) = *(int *)(param_1 + 0x18) + uVar5;

      if ((*(byte *)(param_1 + 4) & 1) != 0) {

        for (uVar4 = uVar5 >> 2; uVar4 != 0; uVar4 = uVar4 - 1) {

          *puVar3 = 0;

          puVar3 = puVar3 + 1;

        }

        for (uVar5 = uVar5 & 3; uVar5 != 0; uVar5 = uVar5 - 1) {

          *(undefined1 *)puVar3 = 0;

          puVar3 = (undefined4 *)((int)puVar3 + 1);

        }

      }

    }

  }

  return;

}





// --- FUN_0040ad90 at 0x0040AD90 (size: 151) ---


undefined4 * __thiscall FUN_0040ad90(undefined4 *param_1,uint param_2)



{

  undefined *puVar1;

  uint *puVar2;

  undefined4 uVar3;

  uint uVar4;

  int iVar5;

  undefined4 *puVar6;

  uint local_4;

  

  local_4 = param_2;

  param_2 = param_2 & 0xffffff00;

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  *param_1 = &PTR_FUN_0079542c;

  puVar1 = PTR_DAT_00818558;

  puVar2 = (uint *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,param_2,0);

  if (puVar2 == (uint *)puVar1) {

    puVar2 = puVar2 + -1;

  }

  uVar4 = *puVar2;

  param_1[0x1a] = uVar4;

  if (uVar4 < 0x18) {

    param_1[0x18] = param_1 + 1;

  }

  else {

    uVar3 = thunk_FUN_005df0f5(uVar4 * 4);

    param_1[0x18] = uVar3;

  }

  param_1[0x19] = (undefined4 *)param_1[0x18] + param_1[0x1a];

  puVar6 = (undefined4 *)param_1[0x18];

  for (uVar4 = param_1[0x1a] & 0x3fffffff; uVar4 != 0; uVar4 = uVar4 - 1) {

    *puVar6 = 0;

    puVar6 = puVar6 + 1;

  }

  for (iVar5 = 0; iVar5 != 0; iVar5 = iVar5 + -1) {

    *(undefined1 *)puVar6 = 0;

    puVar6 = (undefined4 *)((int)puVar6 + 1);

  }

  return param_1;

}





// --- FUN_0040ae30 at 0x0040AE30 (size: 127) ---


undefined4 * __fastcall FUN_0040ae30(undefined4 *param_1)



{

  *param_1 = &PTR_LAB_00795434;

  param_1[2] = 1;

  param_1[1] = &PTR_LAB_00793b6c;

  FUN_0040ad90(0);

  param_1[0x1f] = 0;

  param_1[0x20] = 0;

  param_1[0x21] = DAT_008377a8;

  param_1[0x22] = 0;

  param_1[0x23] = 0;

  param_1[0x24] = 0;

  param_1[0x25] = &PTR_LAB_00795430;

  param_1[0x28] = 0;

  param_1[0x26] = param_1 + 0x29;

  param_1[0x27] = 8;

  param_1[0x39] = 1;

  return param_1;

}





// --- FUN_0040aec0 at 0x0040AEC0 (size: 43) ---


int __fastcall FUN_0040aec0(void *param_1)



{

  int iVar1;

  

  iVar1 = FUN_00401ea0();

  if ((iVar1 == 0) && (param_1 != (void *)0x0)) {

    FUN_004110c0();

    operator_delete(param_1);

  }

  return iVar1;

}





// --- FUN_0040af20 at 0x0040AF20 (size: 143) ---


void __fastcall FUN_0040af20(int param_1)



{

  int iVar1;

  int iVar2;

  int *piVar3;

  void *pvVar4;

  void *pvVar5;

  void *pvVar6;

  int *piVar7;

  

  iVar1 = *(int *)(param_1 + 0x1c);

  if (iVar1 != 0) {

    iVar2 = *(int *)(iVar1 + 0x70);

    while (iVar2 != 0) {

      piVar7 = *(int **)(iVar1 + 0x68);

      while (piVar7 != (int *)(*(int *)(iVar1 + 100) + *(int *)(iVar1 + 0x6c) * 4)) {

        if (**(int **)(iVar1 + 0x68) != 0) {

          piVar7 = *(int **)(iVar1 + 0x68);

          pvVar6 = (void *)*piVar7;

          goto LAB_0040af64;

        }

        piVar7 = *(int **)(iVar1 + 0x68) + 1;

        *(int **)(iVar1 + 0x68) = piVar7;

      }

      piVar7 = (int *)0x0;

      pvVar6 = (void *)0x0;

LAB_0040af64:

      iVar1 = *(int *)(param_1 + 0x1c);

      pvVar5 = (void *)*piVar7;

      piVar3 = *(int **)((int)pvVar6 + 8);

      if (pvVar5 == pvVar6) {

LAB_0040af80:

        *piVar7 = *(int *)((int)pvVar5 + 4);

      }

      else {

        do {

          pvVar4 = pvVar5;

          pvVar5 = *(void **)((int)pvVar4 + 4);

        } while (pvVar5 != pvVar6);

        if (pvVar4 == (void *)0x0) goto LAB_0040af80;

        *(undefined4 *)((int)pvVar4 + 4) = *(undefined4 *)((int)pvVar5 + 4);

      }

      piVar7 = (int *)(iVar1 + 0x70);

      *piVar7 = *piVar7 + -1;

      operator_delete(pvVar6);

      (**(code **)(*piVar3 + 0x14))();

      iVar1 = *(int *)(param_1 + 0x1c);

      iVar2 = *(int *)(iVar1 + 0x70);

    }

  }

  return;

}





// --- FUN_0040afb0 at 0x0040AFB0 (size: 99) ---


void __thiscall FUN_0040afb0(int *param_1,undefined4 *param_2,undefined4 param_3)



{

  int iVar1;

  

  iVar1 = FUN_00406dc0();

  if (iVar1 == 1) {

    iVar1 = FUN_00406db0();

    if (iVar1 == 0) goto LAB_0040afe9;

  }

  FUN_0040af20();

  FUN_00406f90();

  FUN_004070d0(param_3);

LAB_0040afe9:

  param_1[1] = param_1[1] & 0xfffffffbU | 1;

  param_1[6] = 0;

  param_1[2] = 0;

  (**(code **)(*param_1 + 0xc))();

  (**(code **)*param_2)(param_1);

  return;

}





// --- FUN_0040b020 at 0x0040B020 (size: 64) ---


void __thiscall FUN_0040b020(int *param_1,undefined4 *param_2,undefined4 param_3)



{

  FUN_0040af20();

  FUN_00406f90();

  FUN_004070d0(param_3);

  param_1[1] = param_1[1] & 0xfffffffa;

  param_1[6] = 0;

  param_1[2] = 0;

  (**(code **)(*param_1 + 0xc))();

  (**(code **)*param_2)(param_1);

  return;

}





// --- FUN_0040b060 at 0x0040B060 (size: 73) ---


void __fastcall FUN_0040b060(undefined4 *param_1)



{

  *param_1 = &PTR_FUN_00793b3c;

  FUN_0040af20();

  FUN_00406f90();

  if ((undefined4 *)param_1[7] != (undefined4 *)0x0) {

    (*(code *)**(undefined4 **)param_1[7])(1);

  }

  param_1[7] = 0;

  if ((int *)param_1[8] != (int *)0x0) {

    (**(code **)(*(int *)param_1[8] + 0x14))();

    param_1[8] = 0;

  }

  FUN_00406f90();

  return;

}





// --- FUN_0040b0b0 at 0x0040B0B0 (size: 49) ---


void FUN_0040b0b0(undefined1 *param_1,int param_2)



{

  undefined1 *puVar1;

  

  FUN_0040ad10(1);

  puVar1 = (undefined1 *)FUN_0040acf0(1);

  if (puVar1 != (undefined1 *)0x0) {

    if ((*(byte *)(param_2 + 4) & 1) != 0) {

      *puVar1 = *param_1;

      return;

    }

    *param_1 = *puVar1;

  }

  return;

}





// --- FUN_0040b0f0 at 0x0040B0F0 (size: 83) ---


undefined4 __thiscall FUN_0040b0f0(undefined4 *param_1,uint param_2)



{

  int iVar1;

  uint uVar2;

  undefined4 uVar3;

  

  if ((int)param_2 < 0) {

    FUN_0040b0f0(param_2);

    if ((uint)param_1[1] < param_2) {

      param_1[1] = 0;

    }

    else {

      param_1[1] = param_1[1] - param_2;

    }

  }

  iVar1 = param_1[1];

  uVar2 = (**(code **)*param_1)();

  if (uVar2 < iVar1 + param_2) {

    uVar3 = (**(code **)*param_1)();

    param_1[1] = uVar3;

    return 0;

  }

  param_1[1] = iVar1 + param_2;

  return 1;

}





// --- FUN_0040b150 at 0x0040B150 (size: 83) ---


undefined4 __thiscall FUN_0040b150(undefined4 *param_1,uint param_2)



{

  int iVar1;

  uint uVar2;

  undefined4 uVar3;

  

  if ((int)param_2 < 0) {

    FUN_0040b150(param_2);

    if ((uint)param_1[1] < param_2) {

      param_1[1] = 0;

    }

    else {

      param_1[1] = param_1[1] - param_2;

    }

  }

  iVar1 = param_1[1];

  uVar2 = (**(code **)*param_1)();

  if (uVar2 < iVar1 + param_2) {

    uVar3 = (**(code **)*param_1)();

    param_1[1] = uVar3;

    return 0;

  }

  param_1[1] = iVar1 + param_2;

  return 1;

}





// --- FUN_0040b1b0 at 0x0040B1B0 (size: 39) ---


undefined4 __thiscall FUN_0040b1b0(undefined4 *param_1,uint param_2)



{

  uint uVar1;

  undefined4 uVar2;

  

  uVar1 = (**(code **)*param_1)();

  if (uVar1 < param_2) {

    uVar2 = (**(code **)*param_1)();

    param_1[2] = uVar2;

    return 0;

  }

  param_1[2] = param_2;

  return 1;

}





// --- FUN_0040b1e0 at 0x0040B1E0 (size: 57) ---


ushort * FUN_0040b1e0(ushort *param_1,uint param_2,uint param_3)



{

  ushort uVar1;

  bool bVar2;

  

  uVar1 = *param_1;

  bVar2 = false;

  while( true ) {

    if (uVar1 == 0) {

      return (ushort *)0x0;

    }

    if ((uVar1 == param_2) && (!bVar2)) break;

    bVar2 = uVar1 == param_3;

    uVar1 = param_1[1];

    param_1 = param_1 + 1;

  }

  return param_1;

}





// --- FUN_0040b220 at 0x0040B220 (size: 65) ---


void __fastcall FUN_0040b220(int *param_1)



{

  undefined *puVar1;

  LONG LVar2;

  LONG *lpAddend;

  

  puVar1 = (undefined *)*param_1;

  if (puVar1 != PTR_DAT_00818340) {

    LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(puVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar1 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

    *param_1 = (int)PTR_DAT_00818340;

    InterlockedIncrement(lpAddend);

  }

  return;

}





// --- FUN_0040b270 at 0x0040B270 (size: 171) ---


uint FUN_0040b270(int *param_1,char *param_2,char param_3)



{

  char cVar1;

  int iVar2;

  uint uVar3;

  uint uVar4;

  char *pcVar5;

  char *pcVar6;

  

  if (param_3 == '\0') {

    iVar2 = *param_1;

    uVar3 = *(uint *)(iVar2 + -4);

    uVar4 = 0;

    if (uVar3 != 1 && -1 < (int)(uVar3 - 1)) {

      cVar1 = *param_2;

      pcVar6 = param_2;

      do {

        while (cVar1 != '\0') {

          pcVar5 = (char *)(iVar2 + -1 + uVar3);

          if (uVar4 < uVar3) {

            pcVar5 = (char *)(iVar2 + uVar4);

          }

          if (*pcVar5 == cVar1) {

            return uVar4;

          }

          cVar1 = pcVar6[1];

          pcVar6 = pcVar6 + 1;

        }

        uVar4 = uVar4 + 1;

        cVar1 = *param_2;

        pcVar6 = param_2;

      } while ((int)uVar4 < (int)(uVar3 - 1));

    }

  }

  else {

    iVar2 = *param_1;

    uVar4 = *(uint *)(iVar2 + -4);

    uVar3 = uVar4 - 1;

    if (0 < (int)uVar3) {

      do {

        uVar3 = uVar3 - 1;

        cVar1 = *param_2;

        pcVar6 = param_2;

        while (cVar1 != '\0') {

          pcVar5 = (char *)(iVar2 + -1 + uVar4);

          if (uVar3 < uVar4) {

            pcVar5 = (char *)(iVar2 + uVar3);

          }

          if (*pcVar5 == cVar1) {

            return uVar3;

          }

          pcVar5 = pcVar6 + 1;

          pcVar6 = pcVar6 + 1;

          cVar1 = *pcVar5;

        }

        if ((int)uVar3 < 1) {

          return 0xffffffff;

        }

      } while( true );

    }

  }

  return 0xffffffff;

}





// --- FUN_0040b320 at 0x0040B320 (size: 29) ---


bool FUN_0040b320(undefined4 *param_1,int param_2)



{

  int iVar1;

  

  iVar1 = _access((char *)*param_1,param_2);

  return iVar1 == 0;

}





// --- FUN_0040b340 at 0x0040B340 (size: 23) ---


void FUN_0040b340(void)



{

  FUN_0040b1e0();

  return;

}





// --- FUN_0040b360 at 0x0040B360 (size: 29) ---


undefined4 __thiscall FUN_0040b360(int param_1,uint param_2)



{

  int iVar1;

  undefined3 uVar2;

  

  iVar1 = **(int **)(param_1 + 0xc);

  uVar2 = (undefined3)((uint)iVar1 >> 8);

  if (*(uint *)(iVar1 + -4) <= param_2) {

    return CONCAT31(uVar2,*(undefined1 *)((*(uint *)(iVar1 + -4) - 1) + iVar1));

  }

  return CONCAT31(uVar2,*(undefined1 *)(iVar1 + param_2));

}





// --- FUN_0040b3d0 at 0x0040B3D0 (size: 31) ---


undefined4 __thiscall FUN_0040b3d0(int param_1,uint param_2)



{

  int iVar1;

  undefined2 uVar2;

  

  iVar1 = **(int **)(param_1 + 0xc);

  uVar2 = (undefined2)((uint)iVar1 >> 0x10);

  if (*(uint *)(iVar1 + -4) <= param_2) {

    return CONCAT22(uVar2,*(undefined2 *)(iVar1 + -2 + *(uint *)(iVar1 + -4) * 2));

  }

  return CONCAT22(uVar2,*(undefined2 *)(iVar1 + param_2 * 2));

}





// --- FUN_0040b3f0 at 0x0040B3F0 (size: 12) ---


int __fastcall FUN_0040b3f0(int param_1)



{

  return *(int *)(**(int **)(param_1 + 0xc) + -4) + -1;

}





// --- FUN_0040b400 at 0x0040B400 (size: 383) ---


bool FUN_0040b400(undefined4 param_1,int *param_2)



{

  uint uVar1;

  char cVar2;

  char cVar3;

  uint uVar4;

  int iVar5;

  uint uVar6;

  int iVar7;

  int *unaff_retaddr;

  

  cVar2 = (**(code **)(*param_2 + 8))(param_2[1]);

  do {

    if (cVar2 == '\0') {

      cVar2 = (**(code **)(*unaff_retaddr + 8))(unaff_retaddr[1]);

      return cVar2 == '\0';

    }

    cVar2 = (**(code **)(*param_2 + 8))(param_2[1]);

    if (cVar2 == '*') {

      uVar6 = unaff_retaddr[1];

      uVar1 = param_2[1];

      uVar4 = (**(code **)*param_2)();

      if (uVar4 < uVar1 + 1) {

        iVar5 = (**(code **)*param_2)();

        param_2[1] = iVar5;

      }

      else {

        param_2[1] = uVar1 + 1;

      }

      cVar2 = FUN_0040b400(unaff_retaddr,param_2);

      if (cVar2 != '\0') {

        return true;

      }

      uVar4 = (**(code **)*unaff_retaddr)();

      if (uVar4 < uVar6) {

        iVar5 = (**(code **)*unaff_retaddr)();

        unaff_retaddr[1] = iVar5;

      }

      else {

        unaff_retaddr[1] = uVar6;

      }

      uVar6 = (**(code **)*param_2)();

      if (uVar6 < uVar1) {

        iVar5 = (**(code **)*param_2)();

        param_2[1] = iVar5;

      }

      else {

        param_2[1] = uVar1;

      }

      iVar5 = unaff_retaddr[1];

      uVar6 = (**(code **)*unaff_retaddr)();

      if (uVar6 < iVar5 + 1U) {

        iVar5 = (**(code **)*unaff_retaddr)();

        unaff_retaddr[1] = iVar5;

        return false;

      }

      unaff_retaddr[1] = iVar5 + 1U;

    }

    else {

      cVar2 = (**(code **)(*param_2 + 8))(param_2[1]);

      if (cVar2 != '?') {

        cVar2 = (**(code **)(*unaff_retaddr + 8))(unaff_retaddr[1]);

        cVar3 = (**(code **)(*param_2 + 8))(param_2[1]);

        iVar5 = tolower((int)cVar3);

        iVar7 = tolower((int)cVar2);

        if (iVar5 != iVar7) {

          return false;

        }

      }

      iVar5 = unaff_retaddr[1];

      uVar6 = (**(code **)*unaff_retaddr)();

      if (uVar6 < iVar5 + 1U) {

        iVar5 = (**(code **)*unaff_retaddr)();

        unaff_retaddr[1] = iVar5;

      }

      else {

        unaff_retaddr[1] = iVar5 + 1U;

      }

      iVar5 = param_2[1];

      uVar6 = (**(code **)*param_2)();

      if (uVar6 < iVar5 + 1U) {

        iVar5 = (**(code **)*param_2)();

        param_2[1] = iVar5;

      }

      else {

        param_2[1] = iVar5 + 1U;

      }

    }

    cVar2 = (**(code **)(*param_2 + 8))(param_2[1]);

  } while( true );

}





// --- FUN_0040b580 at 0x0040B580 (size: 152) ---


undefined4 __thiscall FUN_0040b580(int *param_1,char param_2,char param_3)



{

  char cVar1;

  int iVar2;

  uint uVar3;

  char unaff_retaddr;

  

  if (param_3 == '\0') {

    cVar1 = (**(code **)(*param_1 + 8))(param_1[1]);

    while( true ) {

      if (cVar1 == unaff_retaddr) {

        return 1;

      }

      iVar2 = param_1[1];

      uVar3 = (**(code **)*param_1)();

      if (uVar3 < iVar2 + 1U) {

        iVar2 = (**(code **)*param_1)();

        param_1[1] = iVar2;

      }

      else {

        param_1[1] = iVar2 + 1U;

      }

      cVar1 = (**(code **)(*param_1 + 8))(param_1[1]);

      if (cVar1 == '\0') break;

      cVar1 = (**(code **)(*param_1 + 8))(param_1[1]);

    }

  }

  else {

    while (param_1[1] != 0) {

      iVar2 = param_1[1] + -1;

      param_1[1] = iVar2;

      cVar1 = (**(code **)(*param_1 + 8))(iVar2);

      if (cVar1 == param_2) {

        return 1;

      }

    }

    param_1[1] = 0;

  }

  return 0;

}





// --- FUN_0040b620 at 0x0040B620 (size: 158) ---


undefined4 __thiscall FUN_0040b620(int *param_1,short param_2,char param_3)



{

  short sVar1;

  int iVar2;

  uint uVar3;

  short unaff_retaddr;

  

  if (param_3 == '\0') {

    sVar1 = (**(code **)(*param_1 + 8))(param_1[1]);

    while( true ) {

      if (sVar1 == unaff_retaddr) {

        return 1;

      }

      iVar2 = param_1[1];

      uVar3 = (**(code **)*param_1)();

      if (uVar3 < iVar2 + 1U) {

        iVar2 = (**(code **)*param_1)();

        param_1[1] = iVar2;

      }

      else {

        param_1[1] = iVar2 + 1U;

      }

      sVar1 = (**(code **)(*param_1 + 8))(param_1[1]);

      if (sVar1 == 0) break;

      sVar1 = (**(code **)(*param_1 + 8))(param_1[1]);

    }

  }

  else {

    while (param_1[1] != 0) {

      iVar2 = param_1[1] + -1;

      param_1[1] = iVar2;

      sVar1 = (**(code **)(*param_1 + 8))(iVar2);

      if (sVar1 == param_2) {

        return 1;

      }

    }

    param_1[1] = 0;

  }

  return 0;

}





// --- FUN_0040b6c0 at 0x0040B6C0 (size: 81) ---


undefined4 FUN_0040b6c0(int *param_1)



{

  char cVar1;

  int iVar2;

  char cVar3;

  undefined *puVar4;

  

  iVar2 = (**(code **)*param_1)();

  param_1[1] = iVar2;

  param_1[2] = iVar2;

  while( true ) {

    if (param_1[1] == 0) {

      param_1[1] = 0;

      return 0;

    }

    iVar2 = param_1[1] + -1;

    param_1[1] = iVar2;

    cVar1 = (**(code **)(*param_1 + 8))(iVar2);

    if (cVar1 == '.') break;

    puVar4 = &DAT_00795474;

    cVar3 = '\\';

    do {

      if (cVar3 == cVar1) {

        return 0;

      }

      cVar3 = puVar4[1];

      puVar4 = puVar4 + 1;

    } while (cVar3 != '\0');

  }

  return 1;

}





// --- FUN_0040b720 at 0x0040B720 (size: 109) ---


undefined4 __thiscall FUN_0040b720(int param_1,int *param_2)



{

  int iVar1;

  int *piVar2;

  

  piVar2 = (int *)FUN_005df0f5(0xc);

  if (piVar2 == (int *)0x0) {

    return 0;

  }

  iVar1 = *param_2;

  *piVar2 = iVar1;

  InterlockedIncrement((LONG *)(iVar1 + -0x10));

  piVar2[1] = 0;

  piVar2[2] = 0;

  if (*(int *)(param_1 + 4) == 0) {

    *(int *)(param_1 + 0xc) = *(int *)(param_1 + 0xc) + 1;

    *(int **)(param_1 + 4) = piVar2;

    *(int **)(param_1 + 8) = piVar2;

    return 1;

  }

  iVar1 = *(int *)(param_1 + 8);

  *(int **)(iVar1 + 4) = piVar2;

  piVar2[2] = iVar1;

  *(int *)(param_1 + 0xc) = *(int *)(param_1 + 0xc) + 1;

  *(int **)(param_1 + 8) = piVar2;

  return 1;

}





// --- FUN_0040b790 at 0x0040B790 (size: 218) ---


undefined4 __thiscall FUN_0040b790(int *param_1,undefined4 param_2,char param_3)



{

  char cVar1;

  int iVar2;

  undefined4 uVar3;

  uint uVar4;

  undefined4 uVar5;

  

  if (param_3 == '\0') {

    iVar2 = param_1[1];

    uVar3 = (**(code **)(*param_1 + 8))(iVar2,0);

    cVar1 = FUN_0040b580(uVar3,iVar2);

    while( true ) {

      if (cVar1 != '\0') {

        return 1;

      }

      iVar2 = param_1[1];

      uVar4 = (**(code **)*param_1)();

      if (uVar4 < iVar2 + 1U) {

        iVar2 = (**(code **)*param_1)();

        param_1[1] = iVar2;

      }

      else {

        param_1[1] = iVar2 + 1U;

      }

      iVar2 = param_1[1];

      cVar1 = (**(code **)(*param_1 + 8))(iVar2);

      if (cVar1 == '\0') break;

      uVar3 = (**(code **)(*param_1 + 8))(param_1[1],0);

      cVar1 = FUN_0040b580(uVar3,iVar2);

    }

  }

  else {

    while (param_1[1] != 0) {

      iVar2 = param_1[1] + -1;

      uVar5 = 0;

      param_1[1] = iVar2;

      uVar3 = (**(code **)(*param_1 + 8))(iVar2,0);

      cVar1 = FUN_0040b580(uVar3,uVar5);

      if (cVar1 != '\0') {

        return 1;

      }

    }

    param_1[1] = 0;

  }

  return 0;

}





// --- FUN_0040b870 at 0x0040B870 (size: 120) ---


int * __thiscall FUN_0040b870(int *param_1,char param_2)



{

  undefined4 *puVar1;

  LONG *lpAddend;

  

  if (param_2 == '\0') {

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *param_1 = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

    return param_1;

  }

  puVar1 = (undefined4 *)thunk_FUN_005df0f5(0x24);

  if (puVar1 != (undefined4 *)0x0) {

    puVar1[1] = 1;

    *puVar1 = &PTR_LAB_007cae34;

    puVar1[4] = 1;

    puVar1[2] = 1;

    puVar1[3] = 0xffffffff;

    *(undefined1 *)(puVar1 + 5) = 0;

    *param_1 = (int)(puVar1 + 5);

    puVar1[4] = 2;

    *(undefined4 *)(*param_1 + -0xc) = 0x10;

  }

  *(char *)*param_1 = param_2;

  *(undefined1 *)(*param_1 + 1) = 0;

  return param_1;

}





// --- FUN_0040b8f0 at 0x0040B8F0 (size: 42) ---


void FUN_0040b8f0(wchar_t *param_1)



{

  size_t sVar1;

  

  if ((param_1 != (wchar_t *)0x0) && (*param_1 != L'\0')) {

    sVar1 = wcslen(param_1);

    FUN_00402490(param_1,sVar1);

  }

  return;

}





// --- FUN_0040b920 at 0x0040B920 (size: 127) ---


undefined4 __fastcall FUN_0040b920(int *param_1)



{

  uint uVar1;

  undefined *puVar2;

  undefined4 uVar3;

  LONG LVar4;

  LONG *lpAddend;

  int iVar5;

  int *unaff_retaddr;

  

  uVar1 = param_1[2];

  if (uVar1 < (uint)param_1[1]) {

    iVar5 = param_1[1] - uVar1;

    uVar3 = (**(code **)(*param_1 + 4))(uVar1);

  }

  else {

    iVar5 = uVar1 - param_1[1];

    uVar3 = (**(code **)(*param_1 + 4))(param_1[1]);

  }

  puVar2 = (undefined *)*unaff_retaddr;

  if (puVar2 != PTR_DAT_00818340) {

    LVar4 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

    if ((LVar4 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

    *unaff_retaddr = (int)PTR_DAT_00818340;

    InterlockedIncrement(lpAddend);

  }

  if (iVar5 != 0) {

    FUN_00402490(uVar3,iVar5);

  }

  return 1;

}





// --- FUN_0040b9a0 at 0x0040B9A0 (size: 93) ---


undefined4 * FUN_0040b9a0(undefined4 *param_1)



{

  undefined *puVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined *local_4;

  

  local_4 = PTR_DAT_00818340;

  InterlockedIncrement((LONG *)(PTR_DAT_00818340 + -0x10));

  FUN_0040b920(&local_4);

  puVar1 = local_4;

  *param_1 = local_4;

  InterlockedIncrement((LONG *)(local_4 + -0x10));

  puVar3 = (undefined4 *)(puVar1 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return param_1;

}





// --- FUN_0040ba00 at 0x0040BA00 (size: 148) ---


undefined4 __fastcall FUN_0040ba00(int param_1)



{

  int iVar1;

  int *piVar2;

  undefined *puVar3;

  LONG LVar4;

  LONG *lpAddend;

  

  iVar1 = **(int **)(param_1 + 0xc);

  InterlockedIncrement((LONG *)(iVar1 + -0x10));

  piVar2 = *(int **)(param_1 + 0xc);

  puVar3 = (undefined *)*piVar2;

  if (puVar3 != PTR_DAT_00818340) {

    LVar4 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

    if ((LVar4 == 0) && ((undefined4 *)(puVar3 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar3 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

    *piVar2 = (int)PTR_DAT_00818340;

    InterlockedIncrement(lpAddend);

  }

  if (*(int *)(param_1 + 4) != 0) {

    FUN_00402490(iVar1,*(int *)(param_1 + 4));

  }

  if (*(uint *)(param_1 + 4) < *(uint *)(param_1 + 8)) {

    *(uint *)(param_1 + 8) = *(uint *)(param_1 + 4);

  }

  LVar4 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

  if ((LVar4 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040baa0 at 0x0040BAA0 (size: 288) ---


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



undefined4 FUN_0040baa0(undefined4 param_1,char *param_2)



{

  char *pcVar1;

  undefined4 uVar2;

  int iVar3;

  ulong uVar4;

  undefined1 *puVar5;

  char *pcVar6;

  char local_10;

  char local_f;

  undefined1 local_e;

  

  if ((_DAT_008377d0 & 1) == 0) {

    _DAT_008377d0 = _DAT_008377d0 | 1;

    _DAT_008377ac = &PTR_FUN_00793b3c;

    _DAT_008377b0 = 0;

    _DAT_008377b4 = 0;

    FUN_00406d60();

    _DAT_008377c4 = 0;

    _DAT_008377c8 = 0;

    _DAT_008377cc = 0;

    _DAT_008377ac = &PTR_FUN_00793b50;

    _atexit((_func_4879 *)&LAB_00726b70);

  }

  uVar2 = FUN_00406d60();

  FUN_0040afb0(&PTR_PTR_008183b8,uVar2);

  FUN_00406f90();

  pcVar6 = *(char **)param_2;

  pcVar1 = pcVar6 + *(int *)(pcVar6 + -4) + -1;

  local_e = 0;

  while (pcVar6 < pcVar1) {

    iVar3 = isspace((int)*pcVar6);

    if (iVar3 == 0) {

      local_10 = *pcVar6;

      local_f = pcVar6[1];

      pcVar6 = pcVar6 + 2;

      uVar4 = strtoul(&local_10,&param_2,0x10);

      FUN_0040ad10(1);

      puVar5 = (undefined1 *)FUN_0040acf0(1);

      if ((puVar5 != (undefined1 *)0x0) && ((_DAT_008377b0 & 1) != 0)) {

        *puVar5 = (char)uVar4;

      }

    }

    else {

      pcVar6 = pcVar6 + 1;

    }

  }

  FUN_0040a900(param_1);

  return param_1;

}





// --- FUN_0040bbc0 at 0x0040BBC0 (size: 192) ---


undefined4 * __thiscall FUN_0040bbc0(int *param_1,undefined4 *param_2,int *param_3)



{

  char cVar1;

  undefined *puVar2;

  LONG LVar3;

  char *pcVar4;

  char *pcVar5;

  

  puVar2 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  LVar3 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

  if ((LVar3 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

  }

  FUN_00401280(*(int *)(*param_3 + -4) + -2 + *(int *)(*param_1 + -4));

  pcVar4 = (char *)*param_1;

  pcVar5 = puVar2;

  do {

    cVar1 = *pcVar4;

    *pcVar5 = cVar1;

    pcVar4 = pcVar4 + 1;

    pcVar5 = pcVar5 + 1;

  } while (cVar1 != '\0');

  pcVar5 = (char *)*param_3;

  pcVar4 = puVar2 + *(int *)(*param_1 + -4) + -1;

  do {

    cVar1 = *pcVar5;

    *pcVar4 = cVar1;

    pcVar5 = pcVar5 + 1;

    pcVar4 = pcVar4 + 1;

  } while (cVar1 != '\0');

  *param_2 = puVar2;

  InterlockedIncrement((LONG *)(puVar2 + -0x10));

  LVar3 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

  if ((LVar3 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

  }

  return param_2;

}





// --- FUN_0040bc80 at 0x0040BC80 (size: 368) ---


undefined4 FUN_0040bc80(undefined4 param_1,int param_2)



{

  int iVar1;

  undefined *puVar2;

  char cVar3;

  short sVar4;

  undefined4 *puVar5;

  uint uVar6;

  undefined **ppuVar7;

  LONG LVar8;

  uint uVar9;

  undefined4 *puVar10;

  undefined **ppuVar11;

  

  puVar10 = (undefined4 *)0x0;

  ppuVar11 = &PTR_FUN_0079549c;

  sVar4 = (*(code *)PTR_FUN_007954a4)(0,&PTR_FUN_0079549c,0,0,param_1);

  if (sVar4 != 0) {

    while( true ) {

      puVar2 = PTR_DAT_00818340;

      InterlockedIncrement((LONG *)(PTR_DAT_00818340 + -0x10));

      FUN_0040b620(param_1,0);

      cVar3 = FUN_0040b920(&stack0x00000000);

      if (cVar3 == '\0') break;

      puVar5 = (undefined4 *)FUN_005df0f5(0xc);

      if (puVar5 != (undefined4 *)0x0) {

        *puVar5 = puVar2;

        InterlockedIncrement((LONG *)(puVar2 + -0x10));

        puVar5[1] = 0;

        puVar5[2] = 0;

        if (*(int *)(param_2 + 4) == 0) {

          *(undefined4 **)(param_2 + 4) = puVar5;

        }

        else {

          iVar1 = *(int *)(param_2 + 8);

          *(undefined4 **)(iVar1 + 4) = puVar5;

          puVar5[2] = iVar1;

        }

        *(int *)(param_2 + 0xc) = *(int *)(param_2 + 0xc) + 1;

        *(undefined4 **)(param_2 + 8) = puVar5;

      }

      uVar9 = (int)ppuVar11 + 1;

      uVar6 = (*(code *)*puVar10)();

      if (uVar6 < uVar9) {

        (*(code *)*puVar10)();

      }

      ppuVar11 = (undefined **)((int)ppuVar11 + 1);

      ppuVar7 = (undefined **)(*(code *)*puVar10)();

      if (ppuVar7 < ppuVar11) {

        ppuVar11 = (undefined **)(*(code *)*puVar10)();

      }

      LVar8 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

      if ((LVar8 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

      }

      sVar4 = (*(code *)puVar10[2])(ppuVar11);

      if (sVar4 == 0) {

        return 1;

      }

    }

    LVar8 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

    if ((LVar8 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

    }

  }

  return 1;

}





// --- FUN_0040bdf0 at 0x0040BDF0 (size: 317) ---


undefined4 __thiscall FUN_0040bdf0(int param_1,int *param_2)



{

  uint uVar1;

  int iVar2;

  int *piVar3;

  undefined *puVar4;

  LONG LVar5;

  size_t sVar6;

  int iVar7;

  short *psVar8;

  LONG *lpAddend;

  uint uVar9;

  wchar_t *_Str;

  uint local_4;

  

  uVar1 = *(uint *)(param_1 + 4);

  local_4 = *(uint *)(param_1 + 8);

  uVar9 = uVar1;

  if (uVar1 < local_4) {

    uVar9 = local_4;

    local_4 = uVar1;

  }

  iVar2 = **(int **)(param_1 + 0xc);

  InterlockedIncrement((LONG *)(iVar2 + -0x10));

  piVar3 = *(int **)(param_1 + 0xc);

  puVar4 = (undefined *)*piVar3;

  if (puVar4 != PTR_DAT_00818340) {

    LVar5 = InterlockedDecrement((LONG *)(puVar4 + -0x10));

    if ((LVar5 == 0) && ((undefined4 *)(puVar4 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar4 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818340 + -0x10);

    *piVar3 = (int)PTR_DAT_00818340;

    InterlockedIncrement(lpAddend);

  }

  if (local_4 != 0) {

    FUN_00402490(iVar2,local_4);

  }

  iVar7 = *(int *)(*param_2 + -4);

  if (iVar7 != 1) {

    FUN_00402490(*param_2,iVar7 + -1);

  }

  uVar1 = *(uint *)(iVar2 + -4);

  psVar8 = (short *)(iVar2 + -2 + uVar1 * 2);

  if (uVar9 < uVar1) {

    psVar8 = (short *)(iVar2 + uVar9 * 2);

  }

  if (*psVar8 != 0) {

    _Str = (wchar_t *)(iVar2 + -2 + uVar1 * 2);

    if (uVar9 < uVar1) {

      _Str = (wchar_t *)(iVar2 + uVar9 * 2);

    }

    if ((_Str != (wchar_t *)0x0) && (*_Str != L'\0')) {

      sVar6 = wcslen(_Str);

      FUN_00402490(_Str,sVar6);

    }

  }

  iVar7 = *(int *)(*param_2 + -4) + -1;

  if (*(uint *)(param_1 + 4) == uVar9) {

    *(uint *)(param_1 + 4) = (*(uint *)(param_1 + 4) - (uVar9 - local_4)) + iVar7;

  }

  else {

    *(int *)(param_1 + 8) = *(int *)(param_1 + 8) + (iVar7 - (uVar9 - local_4));

  }

  LVar5 = InterlockedDecrement((LONG *)(iVar2 + -0x10));

  if ((LVar5 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040bf30 at 0x0040BF30 (size: 127) ---


undefined4 __fastcall FUN_0040bf30(int *param_1)



{

  uint uVar1;

  undefined *puVar2;

  undefined4 uVar3;

  LONG LVar4;

  LONG *lpAddend;

  int iVar5;

  int *unaff_retaddr;

  

  uVar1 = param_1[2];

  if (uVar1 < (uint)param_1[1]) {

    iVar5 = param_1[1] - uVar1;

    uVar3 = (**(code **)(*param_1 + 4))(uVar1);

  }

  else {

    iVar5 = uVar1 - param_1[1];

    uVar3 = (**(code **)(*param_1 + 4))(param_1[1]);

  }

  puVar2 = (undefined *)*unaff_retaddr;

  if (puVar2 != PTR_DAT_00818344) {

    LVar4 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

    if ((LVar4 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *unaff_retaddr = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

  }

  if (iVar5 != 0) {

    FUN_00404ef0(uVar3,iVar5);

  }

  return 1;

}





// --- FUN_0040bfb0 at 0x0040BFB0 (size: 93) ---


undefined4 * FUN_0040bfb0(undefined4 *param_1)



{

  undefined *puVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined *local_4;

  

  local_4 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  FUN_0040bf30(&local_4);

  puVar1 = local_4;

  *param_1 = local_4;

  InterlockedIncrement((LONG *)(local_4 + -0x10));

  puVar3 = (undefined4 *)(puVar1 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return param_1;

}





// --- FUN_0040c010 at 0x0040C010 (size: 148) ---


undefined4 __fastcall FUN_0040c010(int param_1)



{

  int iVar1;

  int *piVar2;

  undefined *puVar3;

  LONG LVar4;

  LONG *lpAddend;

  

  iVar1 = **(int **)(param_1 + 0xc);

  InterlockedIncrement((LONG *)(iVar1 + -0x10));

  piVar2 = *(int **)(param_1 + 0xc);

  puVar3 = (undefined *)*piVar2;

  if (puVar3 != PTR_DAT_00818344) {

    LVar4 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

    if ((LVar4 == 0) && ((undefined4 *)(puVar3 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar3 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *piVar2 = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

  }

  if (*(int *)(param_1 + 4) != 0) {

    FUN_00404ef0(iVar1,*(int *)(param_1 + 4));

  }

  if (*(uint *)(param_1 + 4) < *(uint *)(param_1 + 8)) {

    *(uint *)(param_1 + 8) = *(uint *)(param_1 + 4);

  }

  LVar4 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

  if ((LVar4 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040c0b0 at 0x0040C0B0 (size: 208) ---


undefined4 __fastcall FUN_0040c0b0(int param_1)



{

  char cVar1;

  int iVar2;

  int *piVar3;

  undefined *puVar4;

  uint uVar5;

  LONG LVar6;

  char *pcVar7;

  char *pcVar8;

  LONG *lpAddend;

  

  if (*(int *)(param_1 + 4) != 0) {

    iVar2 = **(int **)(param_1 + 0xc);

    InterlockedIncrement((LONG *)(iVar2 + -0x10));

    piVar3 = *(int **)(param_1 + 0xc);

    puVar4 = (undefined *)*piVar3;

    if (puVar4 != PTR_DAT_00818344) {

      LVar6 = InterlockedDecrement((LONG *)(puVar4 + -0x10));

      if ((LVar6 == 0) && ((undefined4 *)(puVar4 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(puVar4 + -0x14))(1);

      }

      lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

      *piVar3 = (int)PTR_DAT_00818344;

      InterlockedIncrement(lpAddend);

    }

    uVar5 = *(uint *)(iVar2 + -4) - 1;

    if (*(uint *)(param_1 + 4) < *(uint *)(iVar2 + -4)) {

      uVar5 = *(uint *)(param_1 + 4);

    }

    pcVar8 = (char *)(uVar5 + iVar2);

    if ((pcVar8 != (char *)0x0) && (*pcVar8 != '\0')) {

      pcVar7 = pcVar8;

      do {

        cVar1 = *pcVar7;

        pcVar7 = pcVar7 + 1;

      } while (cVar1 != '\0');

      FUN_00404ef0(pcVar8,(int)pcVar7 - (int)(pcVar8 + 1));

    }

    if (*(uint *)(param_1 + 8) < *(uint *)(param_1 + 4)) {

      *(undefined4 *)(param_1 + 8) = 0;

    }

    else {

      *(uint *)(param_1 + 8) = *(uint *)(param_1 + 8) - *(uint *)(param_1 + 4);

    }

    *(undefined4 *)(param_1 + 4) = 0;

    LVar6 = InterlockedDecrement((LONG *)(iVar2 + -0x10));

    if ((LVar6 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

    }

  }

  return 1;

}





// --- FUN_0040c180 at 0x0040C180 (size: 148) ---


undefined4 __thiscall FUN_0040c180(int param_1,int *param_2)



{

  int *piVar1;

  int iVar2;

  LONG LVar3;

  undefined4 *puVar4;

  

  piVar1 = *(int **)(param_1 + 4);

  if (piVar1 == (int *)0x0) {

    return 0;

  }

  iVar2 = piVar1[1];

  *(int *)(param_1 + 4) = iVar2;

  if (iVar2 == 0) {

    *(undefined4 *)(param_1 + 8) = 0;

  }

  else {

    *(undefined4 *)(iVar2 + 8) = 0;

  }

  iVar2 = *param_2;

  if (iVar2 != *piVar1) {

    LVar3 = InterlockedDecrement((LONG *)(iVar2 + -0x10));

    if ((LVar3 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

    }

    iVar2 = *piVar1;

    *param_2 = iVar2;

    InterlockedIncrement((LONG *)(iVar2 + -0x10));

  }

  puVar4 = (undefined4 *)(*piVar1 + -0x14);

  LVar3 = InterlockedDecrement((LONG *)(*piVar1 + -0x10));

  if ((LVar3 == 0) && (puVar4 != (undefined4 *)0x0)) {

    (**(code **)*puVar4)(1);

  }

  operator_delete(piVar1);

  *(int *)(param_1 + 0xc) = *(int *)(param_1 + 0xc) + -1;

  return 1;

}





// --- thunk_FUN_0040bc80 at 0x0040C220 (size: 5) ---


undefined4 thunk_FUN_0040bc80(undefined4 param_1,int param_2)



{

  int iVar1;

  undefined *puVar2;

  char cVar3;

  short sVar4;

  undefined4 *puVar5;

  uint uVar6;

  undefined **ppuVar7;

  LONG LVar8;

  uint uVar9;

  undefined4 *puVar10;

  undefined **ppuVar11;

  

  puVar10 = (undefined4 *)0x0;

  ppuVar11 = &PTR_FUN_0079549c;

  sVar4 = (*(code *)PTR_FUN_007954a4)(0,&PTR_FUN_0079549c,0,0,param_1);

  if (sVar4 != 0) {

    while( true ) {

      puVar2 = PTR_DAT_00818340;

      InterlockedIncrement((LONG *)(PTR_DAT_00818340 + -0x10));

      FUN_0040b620(param_1,0);

      cVar3 = FUN_0040b920(&stack0x00000000);

      if (cVar3 == '\0') break;

      puVar5 = (undefined4 *)FUN_005df0f5(0xc);

      if (puVar5 != (undefined4 *)0x0) {

        *puVar5 = puVar2;

        InterlockedIncrement((LONG *)(puVar2 + -0x10));

        puVar5[1] = 0;

        puVar5[2] = 0;

        if (*(int *)(param_2 + 4) == 0) {

          *(undefined4 **)(param_2 + 4) = puVar5;

        }

        else {

          iVar1 = *(int *)(param_2 + 8);

          *(undefined4 **)(iVar1 + 4) = puVar5;

          puVar5[2] = iVar1;

        }

        *(int *)(param_2 + 0xc) = *(int *)(param_2 + 0xc) + 1;

        *(undefined4 **)(param_2 + 8) = puVar5;

      }

      uVar9 = (int)ppuVar11 + 1;

      uVar6 = (*(code *)*puVar10)();

      if (uVar6 < uVar9) {

        (*(code *)*puVar10)();

      }

      ppuVar11 = (undefined **)((int)ppuVar11 + 1);

      ppuVar7 = (undefined **)(*(code *)*puVar10)();

      if (ppuVar7 < ppuVar11) {

        ppuVar11 = (undefined **)(*(code *)*puVar10)();

      }

      LVar8 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

      if ((LVar8 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

      }

      sVar4 = (*(code *)puVar10[2])(ppuVar11);

      if (sVar4 == 0) {

        return 1;

      }

    }

    LVar8 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

    if ((LVar8 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

    }

  }

  return 1;

}





// --- FUN_0040c230 at 0x0040C230 (size: 59) ---


undefined4 FUN_0040c230(undefined4 param_1)



{

  CHAR local_104 [260];

  

  local_104[0] = '\0';

  GetModuleFileNameA((HMODULE)0x0,local_104,0x104);

  FUN_00401340(local_104);

  return param_1;

}





// --- FUN_0040c270 at 0x0040C270 (size: 88) ---


/* WARNING: Function: __chkstk replaced with injection: alloca_probe */

/* WARNING: Unable to track spacebase fully for stack */



undefined4 FUN_0040c270(undefined4 *param_1)



{

  undefined4 uVar1;

  int iVar2;

  uint uVar3;

  uint uVar4;

  undefined1 *puVar5;

  undefined4 auStack_2c [2];

  undefined1 auStack_24 [4];

  uint uStack_20;

  undefined4 uStack_1c;

  undefined4 uStack_18;

  undefined4 uStack_14;

  

  uStack_1c = *param_1;

  uStack_14 = 0;

  uStack_18 = 0;

  uStack_20 = 0x40c286;

  uVar3 = (*(code *)PTR_FUN_00837384)();

  if (uVar3 != 0) {

    uStack_20 = 0x40c29a;

    iVar2 = -(uVar3 * 2 + 5 & 0xfffffffc);

    uVar1 = *param_1;

    *(uint *)((int)&uStack_20 + iVar2) = uVar3;

    *(int *)(auStack_24 + iVar2) = (int)&uStack_1c + iVar2;

    *(undefined4 *)((int)auStack_2c + iVar2 + 4) = uVar1;

    puVar5 = (undefined1 *)((int)auStack_2c + iVar2);

    *(undefined4 *)((int)auStack_2c + iVar2) = 0x40c2a7;

    uVar4 = (*(code *)PTR_FUN_00837384)();

    if (uVar4 < uVar3) {

      *(int *)((int)puVar5 + -4) = (int)&uStack_1c + iVar2;

      *(undefined4 *)(puVar5 + -8) = 0x40c2be;

      FUN_00407e40();

      return 1;

    }

  }

  return 0;

}





// --- FUN_0040c2d0 at 0x0040C2D0 (size: 367) ---


undefined4 FUN_0040c2d0(undefined4 param_1,int param_2)



{

  int iVar1;

  undefined *puVar2;

  char cVar3;

  undefined4 *puVar4;

  uint uVar5;

  undefined **ppuVar6;

  LONG LVar7;

  uint uVar8;

  undefined4 *puVar9;

  undefined **ppuVar10;

  

  puVar9 = (undefined4 *)0x0;

  ppuVar10 = &PTR_FUN_0079548c;

  cVar3 = (*(code *)PTR_FUN_00795494)(0,&PTR_FUN_0079548c,0,0,param_1);

  if (cVar3 != '\0') {

    while( true ) {

      puVar2 = PTR_DAT_00818344;

      InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

      FUN_0040b580(param_1,0);

      cVar3 = FUN_0040bf30(&stack0x00000000);

      if (cVar3 == '\0') break;

      puVar4 = (undefined4 *)FUN_005df0f5(0xc);

      if (puVar4 != (undefined4 *)0x0) {

        *puVar4 = puVar2;

        InterlockedIncrement((LONG *)(puVar2 + -0x10));

        puVar4[1] = 0;

        puVar4[2] = 0;

        if (*(int *)(param_2 + 4) == 0) {

          *(undefined4 **)(param_2 + 4) = puVar4;

        }

        else {

          iVar1 = *(int *)(param_2 + 8);

          *(undefined4 **)(iVar1 + 4) = puVar4;

          puVar4[2] = iVar1;

        }

        *(int *)(param_2 + 0xc) = *(int *)(param_2 + 0xc) + 1;

        *(undefined4 **)(param_2 + 8) = puVar4;

      }

      uVar8 = (int)ppuVar10 + 1;

      uVar5 = (*(code *)*puVar9)();

      if (uVar5 < uVar8) {

        (*(code *)*puVar9)();

      }

      ppuVar10 = (undefined **)((int)ppuVar10 + 1);

      ppuVar6 = (undefined **)(*(code *)*puVar9)();

      if (ppuVar6 < ppuVar10) {

        ppuVar10 = (undefined **)(*(code *)*puVar9)();

      }

      LVar7 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

      if ((LVar7 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

      }

      cVar3 = (*(code *)puVar9[2])(ppuVar10);

      if (cVar3 == '\0') {

        return 1;

      }

    }

    LVar7 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

    if ((LVar7 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

    }

  }

  return 1;

}





// --- FUN_0040c440 at 0x0040C440 (size: 120) ---


undefined1 __thiscall FUN_0040c440(int *param_1,int *param_2)



{

  int *piVar1;

  int iVar2;

  char cVar3;

  undefined4 uVar4;

  LONG LVar5;

  

  if ((param_1[1] & 0x7fffffffU) <= (uint)param_1[2]) {

    uVar4 = FUN_004077f0((param_1[1] & 0x7fffffffU) + 1);

    cVar3 = FUN_004082c0(uVar4);

    if (cVar3 == '\0') {

      return 0;

    }

  }

  piVar1 = (int *)(*param_1 + param_1[2] * 4);

  iVar2 = *piVar1;

  if (iVar2 != *param_2) {

    LVar5 = InterlockedDecrement((LONG *)(iVar2 + -0x10));

    if ((LVar5 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

    }

    iVar2 = *param_2;

    *piVar1 = iVar2;

    InterlockedIncrement((LONG *)(iVar2 + -0x10));

  }

  param_1[2] = param_1[2] + 1;

  return 1;

}





// --- FUN_0040c4c0 at 0x0040C4C0 (size: 390) ---


undefined4 __thiscall FUN_0040c4c0(int *param_1,int param_2)



{

  uint uVar1;

  int iVar2;

  undefined4 uVar3;

  LONG LVar4;

  int iVar5;

  uint uVar6;

  undefined4 *puVar7;

  bool bVar8;

  uint uStack_8;

  int iStack_4;

  

  iVar2 = (**(code **)(*param_1 + 0xc))();

  if (iVar2 != 0) {

    uVar1 = param_1[1];

    uStack_8 = param_1[2];

    bVar8 = uStack_8 < uVar1;

    uVar6 = uVar1;

    if ((uVar1 < uStack_8) || (uVar6 = uStack_8, uStack_8 = uVar1, bVar8)) {

      uVar3 = FUN_00404f80(&iStack_4,0,uVar6 - 1);

      FUN_00402070(uVar3);

      LVar4 = InterlockedDecrement((LONG *)(iStack_4 + -0x10));

      if ((LVar4 == 0) && ((undefined4 *)(iStack_4 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(iStack_4 + -0x14))(1);

      }

      uVar3 = FUN_00404f80(&param_2,uVar6,uStack_8 - 1);

      FUN_00402070(uVar3);

      puVar7 = (undefined4 *)(param_2 + -0x14);

      LVar4 = InterlockedDecrement((LONG *)(param_2 + -0x10));

      if ((LVar4 == 0) && (puVar7 != (undefined4 *)0x0)) {

        (**(code **)*puVar7)(1);

      }

      uVar3 = (**(code **)*param_1)();

      uVar3 = FUN_00404f80(&param_2,uStack_8,uVar3);

      FUN_00402070(uVar3);

      iVar2 = param_2;

      iVar5 = InterlockedDecrement((LONG *)(param_2 + -0x10));

    }

    else {

      uVar3 = FUN_00404f80(&iStack_4,0,uVar1 - 1);

      FUN_00402070(uVar3);

      LVar4 = InterlockedDecrement((LONG *)(iStack_4 + -0x10));

      if ((LVar4 == 0) && ((undefined4 *)(iStack_4 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(iStack_4 + -0x14))(1);

      }

      FUN_00404cd0();

      uVar3 = (**(code **)*param_1)();

      uVar3 = FUN_00404f80(&param_2,param_1[1],uVar3);

      FUN_00402070(uVar3);

      iVar2 = param_2;

      iVar5 = InterlockedDecrement((LONG *)(param_2 + -0x10));

    }

    if ((iVar5 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

    }

    return 1;

  }

  return 0;

}





// --- FUN_0040c650 at 0x0040C650 (size: 194) ---


undefined4 FUN_0040c650(int *param_1,int *param_2)



{

  uint uVar1;

  uint uVar2;

  int iVar3;

  int *piVar4;

  int *piVar5;

  char cVar6;

  undefined *puVar7;

  char *pcVar8;

  undefined **local_10;

  undefined4 local_c;

  undefined4 local_8;

  int *local_4;

  

  piVar4 = param_1;

  local_10 = &PTR_FUN_0079548c;

  local_4 = param_1;

  local_c = 0;

  local_8 = 0;

  cVar6 = FUN_0040b6c0(&local_10);

  if (cVar6 != '\0') {

    FUN_0040c010();

  }

  piVar5 = param_2;

  uVar2 = *(uint *)(*piVar4 + -4);

  uVar1 = uVar2 - 2;

  if (uVar2 <= uVar1) {

    uVar1 = uVar2 - 1;

  }

  cVar6 = '\\';

  puVar7 = &DAT_00795474;

  do {

    if (cVar6 == *(char *)(uVar1 + *piVar4)) {

      return 0;

    }

    cVar6 = puVar7[1];

    puVar7 = puVar7 + 1;

  } while (cVar6 != '\0');

  pcVar8 = (char *)*param_2;

  if (*(int *)(pcVar8 + -4) != 1) {

    if (*(int *)(pcVar8 + -4) == 0) {

      pcVar8 = pcVar8 + -1;

    }

    if (*pcVar8 != '.') {

      param_1 = (int *)CONCAT31(param_1._1_3_,0x2e);

      FUN_00404ef0(&param_1,1);

    }

  }

  iVar3 = *(int *)(*piVar5 + -4);

  if (iVar3 != 1) {

    FUN_00404ef0(*piVar5,iVar3 + -1);

  }

  return 1;

}





// --- FUN_0040c720 at 0x0040C720 (size: 82) ---


undefined4 FUN_0040c720(undefined4 param_1)



{

  int iVar1;

  

  iVar1 = FUN_0040b270(param_1,&DAT_00795474,1,&PTR_FUN_0079548c,0,0,param_1);

  if (-1 < iVar1) {

    FUN_0040b0f0(iVar1 + 1);

    FUN_0040c0b0();

  }

  return 1;

}





// --- FUN_0040c780 at 0x0040C780 (size: 177) ---


undefined4 FUN_0040c780(int *param_1,undefined4 param_2)



{

  undefined *puVar1;

  int iVar2;

  LONG LVar3;

  LONG *lpAddend;

  

  iVar2 = FUN_0040b270(param_2,&DAT_00795474,1,&PTR_FUN_0079548c,0,0,param_2);

  if (-1 < iVar2) {

    FUN_0040b0f0(iVar2 + 1);

    FUN_0040bf30(param_1);

    return 1;

  }

  puVar1 = (undefined *)*param_1;

  if (puVar1 != PTR_DAT_00818344) {

    LVar3 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

    if ((LVar3 == 0) && ((undefined4 *)(puVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar1 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *param_1 = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

  }

  return 1;

}





// --- FUN_0040c840 at 0x0040C840 (size: 94) ---


undefined4 * FUN_0040c840(undefined4 *param_1,undefined4 param_2)



{

  char cVar1;

  LONG *lpAddend;

  undefined **local_10;

  undefined4 local_c;

  undefined4 local_8;

  undefined4 local_4;

  

  local_4 = param_2;

  local_10 = &PTR_FUN_0079548c;

  local_c = 0;

  local_8 = 0;

  cVar1 = FUN_0040b6c0(&local_10);

  if (cVar1 != '\0') {

    FUN_0040bfb0(param_1);

    return param_1;

  }

  lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

  *param_1 = PTR_DAT_00818344;

  InterlockedIncrement(lpAddend);

  return param_1;

}





// --- FUN_0040c8a0 at 0x0040C8A0 (size: 253) ---


undefined4 __thiscall FUN_0040c8a0(int param_1,int *param_2)



{

  char cVar1;

  int iVar2;

  int *piVar3;

  undefined *puVar4;

  int iVar5;

  LONG LVar6;

  char *pcVar7;

  LONG *lpAddend;

  char *pcVar8;

  

  if (*(int *)(*param_2 + -4) != 1) {

    iVar2 = **(int **)(param_1 + 0xc);

    InterlockedIncrement((LONG *)(iVar2 + -0x10));

    piVar3 = *(int **)(param_1 + 0xc);

    puVar4 = (undefined *)*piVar3;

    if (puVar4 != PTR_DAT_00818344) {

      LVar6 = InterlockedDecrement((LONG *)(puVar4 + -0x10));

      if ((LVar6 == 0) && ((undefined4 *)(puVar4 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(puVar4 + -0x14))(1);

      }

      lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

      *piVar3 = (int)PTR_DAT_00818344;

      InterlockedIncrement(lpAddend);

    }

    if (*(int *)(param_1 + 4) != 0) {

      FUN_00404ef0(iVar2,*(int *)(param_1 + 4));

    }

    iVar5 = *(int *)(*param_2 + -4);

    if (iVar5 != 1) {

      FUN_00404ef0(*param_2,iVar5 + -1);

    }

    pcVar8 = (char *)(*(int *)(param_1 + 4) + iVar2);

    if ((pcVar8 != (char *)0x0) && (*pcVar8 != '\0')) {

      pcVar7 = pcVar8;

      do {

        cVar1 = *pcVar7;

        pcVar7 = pcVar7 + 1;

      } while (cVar1 != '\0');

      FUN_00404ef0(pcVar8,(int)pcVar7 - (int)(pcVar8 + 1));

    }

    if (*(uint *)(param_1 + 4) <= *(uint *)(param_1 + 8)) {

      *(uint *)(param_1 + 8) = *(int *)(*param_2 + -4) + -1 + *(uint *)(param_1 + 8);

    }

    *(uint *)(param_1 + 4) = *(int *)(*param_2 + -4) + -1 + *(uint *)(param_1 + 4);

    LVar6 = InterlockedDecrement((LONG *)(iVar2 + -0x10));

    if ((LVar6 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

    }

  }

  return 1;

}





// --- FUN_0040c9a0 at 0x0040C9A0 (size: 314) ---


undefined4 __thiscall FUN_0040c9a0(int param_1,int *param_2)



{

  char cVar1;

  uint uVar2;

  int iVar3;

  int *piVar4;

  undefined *puVar5;

  uint uVar6;

  LONG LVar7;

  char *pcVar8;

  int iVar9;

  char *pcVar10;

  LONG *lpAddend;

  uint uVar11;

  uint local_4;

  

  uVar2 = *(uint *)(param_1 + 4);

  local_4 = *(uint *)(param_1 + 8);

  uVar11 = uVar2;

  if (uVar2 < local_4) {

    uVar11 = local_4;

    local_4 = uVar2;

  }

  iVar3 = **(int **)(param_1 + 0xc);

  InterlockedIncrement((LONG *)(iVar3 + -0x10));

  piVar4 = *(int **)(param_1 + 0xc);

  puVar5 = (undefined *)*piVar4;

  if (puVar5 != PTR_DAT_00818344) {

    LVar7 = InterlockedDecrement((LONG *)(puVar5 + -0x10));

    if ((LVar7 == 0) && ((undefined4 *)(puVar5 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar5 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *piVar4 = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

  }

  if (local_4 != 0) {

    FUN_00404ef0(iVar3,local_4);

  }

  iVar9 = *(int *)(*param_2 + -4);

  if (iVar9 != 1) {

    FUN_00404ef0(*param_2,iVar9 + -1);

  }

  uVar2 = *(uint *)(iVar3 + -4);

  uVar6 = uVar2 - 1;

  if (uVar11 < uVar2) {

    uVar6 = uVar11;

  }

  if (*(char *)(uVar6 + iVar3) != '\0') {

    uVar6 = uVar2 - 1;

    if (uVar11 < uVar2) {

      uVar6 = uVar11;

    }

    pcVar10 = (char *)(uVar6 + iVar3);

    if ((pcVar10 != (char *)0x0) && (*pcVar10 != '\0')) {

      pcVar8 = pcVar10;

      do {

        cVar1 = *pcVar8;

        pcVar8 = pcVar8 + 1;

      } while (cVar1 != '\0');

      FUN_00404ef0(pcVar10,(int)pcVar8 - (int)(pcVar10 + 1));

    }

  }

  iVar9 = *(int *)(*param_2 + -4) + -1;

  if (*(uint *)(param_1 + 4) == uVar11) {

    *(uint *)(param_1 + 4) = (*(uint *)(param_1 + 4) - (uVar11 - local_4)) + iVar9;

  }

  else {

    *(int *)(param_1 + 8) = *(int *)(param_1 + 8) + (iVar9 - (uVar11 - local_4));

  }

  LVar7 = InterlockedDecrement((LONG *)(iVar3 + -0x10));

  if ((LVar7 == 0) && ((undefined4 *)(iVar3 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(iVar3 + -0x14))(1);

  }

  return 1;

}





// --- thunk_FUN_0040c2d0 at 0x0040CAE0 (size: 5) ---


undefined4 thunk_FUN_0040c2d0(undefined4 param_1,int param_2)



{

  int iVar1;

  undefined *puVar2;

  char cVar3;

  undefined4 *puVar4;

  uint uVar5;

  undefined **ppuVar6;

  LONG LVar7;

  uint uVar8;

  undefined4 *puVar9;

  undefined **ppuVar10;

  

  puVar9 = (undefined4 *)0x0;

  ppuVar10 = &PTR_FUN_0079548c;

  cVar3 = (*(code *)PTR_FUN_00795494)(0,&PTR_FUN_0079548c,0,0,param_1);

  if (cVar3 != '\0') {

    while( true ) {

      puVar2 = PTR_DAT_00818344;

      InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

      FUN_0040b580(param_1,0);

      cVar3 = FUN_0040bf30(&stack0x00000000);

      if (cVar3 == '\0') break;

      puVar4 = (undefined4 *)FUN_005df0f5(0xc);

      if (puVar4 != (undefined4 *)0x0) {

        *puVar4 = puVar2;

        InterlockedIncrement((LONG *)(puVar2 + -0x10));

        puVar4[1] = 0;

        puVar4[2] = 0;

        if (*(int *)(param_2 + 4) == 0) {

          *(undefined4 **)(param_2 + 4) = puVar4;

        }

        else {

          iVar1 = *(int *)(param_2 + 8);

          *(undefined4 **)(iVar1 + 4) = puVar4;

          puVar4[2] = iVar1;

        }

        *(int *)(param_2 + 0xc) = *(int *)(param_2 + 0xc) + 1;

        *(undefined4 **)(param_2 + 8) = puVar4;

      }

      uVar8 = (int)ppuVar10 + 1;

      uVar5 = (*(code *)*puVar9)();

      if (uVar5 < uVar8) {

        (*(code *)*puVar9)();

      }

      ppuVar10 = (undefined **)((int)ppuVar10 + 1);

      ppuVar6 = (undefined **)(*(code *)*puVar9)();

      if (ppuVar6 < ppuVar10) {

        ppuVar10 = (undefined **)(*(code *)*puVar9)();

      }

      LVar7 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

      if ((LVar7 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

        (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

      }

      cVar3 = (*(code *)puVar9[2])(ppuVar10);

      if (cVar3 == '\0') {

        return 1;

      }

    }

    LVar7 = InterlockedDecrement((LONG *)(puVar2 + -0x10));

    if ((LVar7 == 0) && ((undefined4 *)(puVar2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar2 + -0x14))(1);

    }

  }

  return 1;

}





// --- FUN_0040caf0 at 0x0040CAF0 (size: 125) ---


undefined4 FUN_0040caf0(undefined *param_1,int param_2)



{

  uint uVar1;

  uint uVar2;

  undefined *puVar3;

  int iVar4;

  LONG LVar5;

  int iVar6;

  

  iVar6 = param_2;

  uVar2 = (uint)param_1;

  puVar3 = PTR_DAT_00818344;

  uVar1 = (int)param_1 + param_2;

  param_1 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  for (; uVar2 < uVar1; uVar2 = uVar2 + 1 + iVar4) {

    iVar4 = FUN_00402710(&param_1,&DAT_007954d8,iVar6,uVar2);

    iVar6 = iVar6 - iVar4;

    FUN_0040c440(&param_1);

    puVar3 = param_1;

  }

  LVar5 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

  if ((LVar5 == 0) && ((undefined4 *)(puVar3 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(puVar3 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040cb70 at 0x0040CB70 (size: 261) ---


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



void FUN_0040cb70(int *param_1,int *param_2)



{

  uint uVar1;

  int iVar2;

  int iVar3;

  int *piVar4;

  int *piVar5;

  LONG LVar6;

  char *pcVar7;

  

  piVar4 = param_2;

  if (*(int *)(*param_2 + -4) != 1) {

    if ((_DAT_008377d8 & 1) == 0) {

      _DAT_008377d8 = _DAT_008377d8 | 1;

      piVar5 = (int *)FUN_00401340(&DAT_00795470);

      DAT_008377d4 = *piVar5;

      InterlockedIncrement((LONG *)(DAT_008377d4 + -0x10));

      piVar5 = param_2 + -5;

      LVar6 = InterlockedDecrement(param_2 + -4);

      if ((LVar6 == 0) && (piVar5 != (int *)0x0)) {

        (**(code **)*piVar5)(1);

      }

      _atexit((_func_4879 *)&LAB_00726be0);

    }

    iVar2 = *param_1;

    if (*(int *)(iVar2 + -4) == 1) {

      FUN_00405000(&DAT_007954e0);

    }

    else {

      uVar1 = *(uint *)(iVar2 + -4) - 2;

      if (*(uint *)(iVar2 + -4) <= uVar1) {

        uVar1 = *(int *)(iVar2 + -4) - 1;

      }

      pcVar7 = strchr((char *)DAT_008377d4,(int)*(char *)(uVar1 + iVar2));

      if (pcVar7 == (char *)0x0) {

        pcVar7 = (char *)*piVar4;

        if (*(int *)(pcVar7 + -4) == 0) {

          pcVar7 = pcVar7 + -1;

        }

        pcVar7 = strchr((char *)DAT_008377d4,(int)*pcVar7);

        if (pcVar7 == (char *)0x0) {

          param_2 = (int *)CONCAT31(param_2._1_3_,0x2f);

          FUN_00404ef0(&param_2,1);

        }

      }

    }

    iVar2 = *piVar4;

    iVar3 = *(int *)(iVar2 + -4);

    if (iVar3 != 1) {

      FUN_00404ef0(iVar2,iVar3 + -1);

    }

  }

  return;

}





// --- FUN_0040cc80 at 0x0040CC80 (size: 262) ---


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



void FUN_0040cc80(int *param_1,int *param_2)



{

  uint uVar1;

  int iVar2;

  int iVar3;

  int *piVar4;

  LONG LVar5;

  wchar_t *pwVar6;

  int *piVar7;

  undefined4 *puVar8;

  undefined4 uVar9;

  

  piVar4 = param_2;

  if (*(int *)(*param_2 + -4) != 1) {

    if ((_DAT_008377e0 & 1) == 0) {

      _DAT_008377e0 = _DAT_008377e0 | 1;

      uVar9 = 0;

      puVar8 = &DAT_008377dc;

      FUN_00401340(&DAT_00795470);

      FUN_00403350(puVar8,uVar9);

      piVar7 = param_2 + -5;

      LVar5 = InterlockedDecrement(param_2 + -4);

      if ((LVar5 == 0) && (piVar7 != (int *)0x0)) {

        (**(code **)*piVar7)(1);

      }

      _atexit((_func_4879 *)&LAB_00726c10);

    }

    iVar2 = *param_1;

    if (*(int *)(iVar2 + -4) == 1) {

      FUN_00407e40(&DAT_007954e4);

    }

    else {

      uVar1 = *(uint *)(iVar2 + -4) - 2;

      if (uVar1 < *(uint *)(iVar2 + -4)) {

        pwVar6 = (wchar_t *)(iVar2 + uVar1 * 2);

      }

      else {

        pwVar6 = (wchar_t *)(iVar2 + -2 + *(int *)(iVar2 + -4) * 2);

      }

      pwVar6 = wcschr(DAT_008377dc,*pwVar6);

      if (pwVar6 == (wchar_t *)0x0) {

        pwVar6 = (wchar_t *)*piVar4;

        if (*(int *)(pwVar6 + -2) == 0) {

          pwVar6 = pwVar6 + -1;

        }

        pwVar6 = wcschr(DAT_008377dc,*pwVar6);

        if (pwVar6 == (wchar_t *)0x0) {

          param_2 = (int *)0x2f;

          FUN_00402490(&param_2,1);

        }

      }

    }

    iVar2 = *piVar4;

    iVar3 = *(int *)(iVar2 + -4);

    if (iVar3 != 1) {

      FUN_00402490(iVar2,iVar3 + -1);

    }

  }

  return;

}





// --- thunk_FUN_0040c650 at 0x0040CD90 (size: 5) ---


undefined4 thunk_FUN_0040c650(int *param_1,int *param_2)



{

  uint uVar1;

  uint uVar2;

  int iVar3;

  int *piVar4;

  int *piVar5;

  char cVar6;

  undefined *puVar7;

  char *pcVar8;

  undefined **ppuStack_10;

  undefined4 uStack_c;

  undefined4 uStack_8;

  int *piStack_4;

  

  piVar4 = param_1;

  ppuStack_10 = &PTR_FUN_0079548c;

  piStack_4 = param_1;

  uStack_c = 0;

  uStack_8 = 0;

  cVar6 = FUN_0040b6c0(&ppuStack_10);

  if (cVar6 != '\0') {

    FUN_0040c010();

  }

  piVar5 = param_2;

  uVar2 = *(uint *)(*piVar4 + -4);

  uVar1 = uVar2 - 2;

  if (uVar2 <= uVar1) {

    uVar1 = uVar2 - 1;

  }

  cVar6 = '\\';

  puVar7 = &DAT_00795474;

  do {

    if (cVar6 == *(char *)(uVar1 + *piVar4)) {

      return 0;

    }

    cVar6 = puVar7[1];

    puVar7 = puVar7 + 1;

  } while (cVar6 != '\0');

  pcVar8 = (char *)*param_2;

  if (*(int *)(pcVar8 + -4) != 1) {

    if (*(int *)(pcVar8 + -4) == 0) {

      pcVar8 = pcVar8 + -1;

    }

    if (*pcVar8 != '.') {

      param_1 = (int *)CONCAT31(param_1._1_3_,0x2e);

      FUN_00404ef0(&param_1,1);

    }

  }

  iVar3 = *(int *)(*piVar5 + -4);

  if (iVar3 != 1) {

    FUN_00404ef0(*piVar5,iVar3 + -1);

  }

  return 1;

}





// --- FUN_0040cda0 at 0x0040CDA0 (size: 59) ---


undefined4 FUN_0040cda0(undefined4 param_1)



{

  char cVar1;

  undefined **local_10;

  undefined4 local_c;

  undefined4 local_8;

  undefined4 local_4;

  

  local_4 = param_1;

  local_10 = &PTR_FUN_0079548c;

  local_c = 0;

  local_8 = 0;

  cVar1 = FUN_0040b6c0(&local_10);

  if (cVar1 != '\0') {

    FUN_0040c010();

  }

  return 1;

}





// --- thunk_FUN_0040c720 at 0x0040CDE0 (size: 5) ---


undefined4 thunk_FUN_0040c720(undefined4 param_1)



{

  int iVar1;

  

  iVar1 = FUN_0040b270(param_1,&DAT_00795474,1,&PTR_FUN_0079548c,0,0,param_1);

  if (-1 < iVar1) {

    FUN_0040b0f0(iVar1 + 1);

    FUN_0040c0b0();

  }

  return 1;

}





// --- thunk_FUN_0040c780 at 0x0040CDF0 (size: 5) ---


undefined4 thunk_FUN_0040c780(int *param_1,undefined4 param_2)



{

  undefined *puVar1;

  int iVar2;

  LONG LVar3;

  LONG *lpAddend;

  

  iVar2 = FUN_0040b270(param_2,&DAT_00795474,1,&PTR_FUN_0079548c,0,0,param_2);

  if (-1 < iVar2) {

    FUN_0040b0f0(iVar2 + 1);

    FUN_0040bf30(param_1);

    return 1;

  }

  puVar1 = (undefined *)*param_1;

  if (puVar1 != PTR_DAT_00818344) {

    LVar3 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

    if ((LVar3 == 0) && ((undefined4 *)(puVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar1 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *param_1 = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

  }

  return 1;

}





// --- FUN_0040ce00 at 0x0040CE00 (size: 23) ---


undefined4 FUN_0040ce00(undefined4 param_1,undefined4 param_2)



{

  FUN_0040c840(param_1,param_2);

  return param_1;

}





// --- FUN_0040ce20 at 0x0040CE20 (size: 508) ---


undefined4 * FUN_0040ce20(undefined4 *param_1)



{

  byte bVar1;

  char cVar2;

  byte *pbVar3;

  int iVar4;

  char *pcVar5;

  LONG LVar6;

  byte *pbVar7;

  char *pcVar8;

  char *pcVar9;

  char local_24 [4];

  char *local_20;

  byte *local_1c;

  byte *local_18;

  char local_14 [16];

  char local_4;

  

  local_14._4_4_ = s_0123456789ABCDEF_007954ec._4_4_;

  local_14._0_4_ = s_0123456789ABCDEF_007954ec._0_4_;

  local_4 = s_0123456789ABCDEF_007954ec[0x10];

  local_14._8_4_ = s_0123456789ABCDEF_007954ec._8_4_;

  local_14._12_4_ = s_0123456789ABCDEF_007954ec._12_4_;

  pbVar3 = (byte *)FUN_00406d80();

  iVar4 = FUN_00406db0();

  local_20 = PTR_DAT_00818344;

  pbVar7 = pbVar3 + iVar4;

  local_18 = pbVar7;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  iVar4 = FUN_00406db0();

  FUN_00408d90(iVar4 * 2);

  pcVar9 = local_20;

  local_1c = pbVar3;

  if (pbVar3 < pbVar7) {

    do {

      bVar1 = *pbVar3;

      local_24[0] = local_14[bVar1 >> 4];

      pcVar8 = pcVar9;

      local_1c = pbVar3;

      if (local_24[0] != '\0') {

        iVar4 = *(int *)(pcVar9 + -4);

        if ((*(int *)(pcVar9 + -0x10) == 1) && (iVar4 + 1U <= *(uint *)(pcVar9 + -0xc))) {

          *(uint *)(pcVar9 + -4) = iVar4 + 1U;

          pcVar9[-0xffffffff00000008] = -1;

          pcVar9[-0xffffffff00000007] = -1;

          pcVar9[-0xffffffff00000006] = -1;

          pcVar9[-0xffffffff00000005] = -1;

        }

        else {

          FUN_00401280(iVar4);

          pcVar8 = local_20;

          pcVar5 = pcVar9;

          do {

            cVar2 = *pcVar5;

            pcVar5[(int)local_20 - (int)pcVar9] = cVar2;

            pcVar5 = pcVar5 + 1;

          } while (cVar2 != '\0');

          LVar6 = InterlockedDecrement((LONG *)(pcVar9 + -0x10));

          if ((LVar6 == 0) && (pcVar9 + -0x14 != (char *)0x0)) {

            (*(code *)**(undefined4 **)(pcVar9 + -0x14))(1);

          }

        }

        strncpy(pcVar8 + iVar4 + -1,local_24,1);

        pcVar8[*(int *)(pcVar8 + -4) + -1] = '\0';

        pbVar7 = local_18;

      }

      local_24[0] = local_14[bVar1 & 0xf];

      pcVar9 = pcVar8;

      if (local_24[0] != '\0') {

        iVar4 = *(int *)(pcVar8 + -4);

        if ((*(int *)(pcVar8 + -0x10) == 1) && (iVar4 + 1U <= *(uint *)(pcVar8 + -0xc))) {

          *(uint *)(pcVar8 + -4) = iVar4 + 1U;

          pcVar8[-0xffffffff00000008] = -1;

          pcVar8[-0xffffffff00000007] = -1;

          pcVar8[-0xffffffff00000006] = -1;

          pcVar8[-0xffffffff00000005] = -1;

        }

        else {

          FUN_00401280(iVar4);

          pcVar9 = local_20;

          pcVar5 = pcVar8;

          do {

            cVar2 = *pcVar5;

            pcVar5[(int)local_20 - (int)pcVar8] = cVar2;

            pcVar5 = pcVar5 + 1;

          } while (cVar2 != '\0');

          LVar6 = InterlockedDecrement((LONG *)(pcVar8 + -0x10));

          if ((LVar6 == 0) && (pcVar8 + -0x14 != (char *)0x0)) {

            (*(code *)**(undefined4 **)(pcVar8 + -0x14))(1);

          }

        }

        strncpy(pcVar9 + iVar4 + -1,local_24,1);

        pcVar9[*(int *)(pcVar9 + -4) + -1] = '\0';

      }

      pbVar3 = local_1c + 1;

      local_1c = pbVar3;

    } while (pbVar3 < pbVar7);

  }

  *param_1 = pcVar9;

  InterlockedIncrement((LONG *)(pcVar9 + -0x10));

  LVar6 = InterlockedDecrement((LONG *)(pcVar9 + -0x10));

  if ((LVar6 == 0) && (pcVar9 + -0x14 != (char *)0x0)) {

    (*(code *)**(undefined4 **)(pcVar9 + -0x14))(1);

  }

  return param_1;

}





// --- FUN_0040d020 at 0x0040D020 (size: 341) ---


undefined4 FUN_0040d020(int *param_1,uint param_2)



{

  char cVar1;

  int iVar2;

  undefined *puVar3;

  char *pcVar4;

  int iVar5;

  int *piVar6;

  uint uVar7;

  LONG LVar8;

  LONG *lpAddend;

  char *pcVar9;

  char *pcVar10;

  uint uVar11;

  

  piVar6 = param_1;

  iVar2 = *param_1;

  InterlockedIncrement((LONG *)(iVar2 + -0x10));

  puVar3 = (undefined *)*piVar6;

  uVar11 = *(int *)(puVar3 + -4) - 1;

  uVar7 = uVar11 / param_2;

  if (puVar3 != PTR_DAT_00818344) {

    LVar8 = InterlockedDecrement((LONG *)(puVar3 + -0x10));

    if ((LVar8 == 0) && ((undefined4 *)(puVar3 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(puVar3 + -0x14))(1);

    }

    lpAddend = (LONG *)(PTR_DAT_00818344 + -0x10);

    *piVar6 = (int)PTR_DAT_00818344;

    InterlockedIncrement(lpAddend);

  }

  FUN_00408d90(uVar7 + uVar11);

  uVar7 = 0;

  if (uVar11 != 0) {

    do {

      FUN_00404ef0(uVar7 + iVar2,param_2);

      pcVar4 = (char *)*piVar6;

      param_1 = (int *)CONCAT31(param_1._1_3_,10);

      iVar5 = *(int *)(pcVar4 + -4);

      if ((*(int *)(pcVar4 + -0x10) == 1) && (iVar5 + 1U <= *(uint *)(pcVar4 + -0xc))) {

        *(uint *)(pcVar4 + -4) = iVar5 + 1U;

        *(undefined4 *)(*piVar6 + -8) = 0xffffffff;

      }

      else {

        FUN_00401280(iVar5);

        pcVar10 = (char *)*piVar6;

        pcVar9 = pcVar4;

        do {

          cVar1 = *pcVar9;

          *pcVar10 = cVar1;

          pcVar9 = pcVar9 + 1;

          pcVar10 = pcVar10 + 1;

        } while (cVar1 != '\0');

        LVar8 = InterlockedDecrement((LONG *)(pcVar4 + -0x10));

        if ((LVar8 == 0) && (pcVar4 + -0x14 != (char *)0x0)) {

          (*(code *)**(undefined4 **)(pcVar4 + -0x14))(1);

        }

      }

      strncpy((char *)(*piVar6 + -1 + iVar5),(char *)&param_1,1);

      uVar7 = uVar7 + param_2;

      *(undefined1 *)(*(int *)(*piVar6 + -4) + -1 + *piVar6) = 0;

    } while (uVar7 < uVar11);

  }

  LVar8 = InterlockedDecrement((LONG *)(iVar2 + -0x10));

  if ((LVar8 == 0) && ((undefined4 *)(iVar2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(iVar2 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040d180 at 0x0040D180 (size: 115) ---


undefined4 FUN_0040d180(int *param_1)



{

  int iVar1;

  int *piVar2;

  LONG LVar3;

  int local_4;

  

  piVar2 = (int *)FUN_00403350(&local_4,0);

  iVar1 = *param_1;

  if (iVar1 != *piVar2) {

    LVar3 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar3 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    iVar1 = *piVar2;

    *param_1 = iVar1;

    InterlockedIncrement((LONG *)(iVar1 + -0x10));

  }

  LVar3 = InterlockedDecrement((LONG *)(local_4 + -0x10));

  if ((LVar3 == 0) && ((undefined4 *)(local_4 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(local_4 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040d200 at 0x0040D200 (size: 95) ---


undefined4 * FUN_0040d200(undefined4 *param_1,undefined4 param_2)



{

  undefined *puVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined *local_4;

  

  local_4 = PTR_DAT_00818340;

  InterlockedIncrement((LONG *)(PTR_DAT_00818340 + -0x10));

  FUN_0040d180(&local_4,param_2);

  puVar1 = local_4;

  *param_1 = local_4;

  InterlockedIncrement((LONG *)(local_4 + -0x10));

  puVar3 = (undefined4 *)(puVar1 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return param_1;

}





// --- FUN_0040d260 at 0x0040D260 (size: 427) ---


undefined4 FUN_0040d260(undefined4 param_1,int *param_2)



{

  char cVar1;

  int iVar2;

  undefined **ppuVar3;

  undefined4 uVar4;

  undefined4 *puVar5;

  LONG LVar6;

  char cVar7;

  undefined *puVar8;

  int *piVar9;

  undefined4 uStack_24;

  

  piVar9 = param_2;

  uStack_24 = (undefined4 *)CONCAT13(1,(uint3)uStack_24);

  if (*(int *)(*param_2 + -4) == 1) {

LAB_0040d2cf:

    uStack_24 = (undefined4 *)(uint)(uint3)uStack_24;

  }

  else {

    iVar2 = (*(code *)PTR_FUN_0079548c)();

    if (iVar2 == 0) {

      iVar2 = 0;

    }

    else {

      iVar2 = iVar2 + -1;

    }

    cVar1 = (*(code *)PTR_FUN_00795494)(iVar2);

    puVar8 = &DAT_00795474;

    cVar7 = '\\';

    do {

      if (cVar7 == cVar1) goto LAB_0040d2cf;

      cVar7 = puVar8[1];

      puVar8 = puVar8 + 1;

    } while (cVar7 != '\0');

  }

  iVar2 = FUN_0040b270(param_1,&DAT_00795474,1);

  if (iVar2 < 0) {

    FUN_0040c8a0(piVar9);

    if (uStack_24._3_1_ == '\0') {

      return 1;

    }

    puVar5 = (undefined4 *)thunk_FUN_005df0f5(0x24);

    if (puVar5 != (undefined4 *)0x0) {

      param_2 = puVar5 + 5;

      puVar5[1] = 1;

      *puVar5 = &PTR_LAB_007cae34;

      puVar5[4] = 1;

      puVar5[2] = 1;

      puVar5[3] = 0xffffffff;

      *(undefined1 *)param_2 = 0;

      puVar5[4] = 2;

      puVar5[2] = 0x10;

    }

    piVar9 = param_2;

    *(undefined1 *)param_2 = 0x2f;

    *(undefined1 *)((int)param_2 + 1) = 0;

    FUN_0040c8a0(&param_2);

  }

  else {

    FUN_0040b0f0(iVar2);

    (*(code *)PTR_FUN_00795494)(0);

    ppuVar3 = (undefined **)(*(code *)*uStack_24)();

    if (ppuVar3 <= &PTR_FUN_0079548c) {

      (*(code *)PTR_FUN_0079548c)();

    }

    FUN_0040c0b0();

    FUN_0040c8a0(piVar9);

    if (uStack_24._3_1_ == '\0') {

      return 1;

    }

    uVar4 = FUN_0040b870(param_2);

    FUN_0040c8a0(uVar4);

    piVar9 = param_2;

  }

  LVar6 = InterlockedDecrement(piVar9 + -4);

  if ((LVar6 == 0) && (piVar9 + -5 != (int *)0x0)) {

    (**(code **)piVar9[-5])(1);

  }

  return 1;

}





// --- FUN_0040d410 at 0x0040D410 (size: 89) ---


void __fastcall FUN_0040d410(int param_1)



{

  LONG LVar1;

  undefined4 *puVar2;

  undefined *local_4;

  

  while (*(int *)(param_1 + 4) != 0) {

    local_4 = PTR_DAT_00818340;

    InterlockedIncrement((LONG *)(PTR_DAT_00818340 + -0x10));

    FUN_0040c180(&local_4);

    puVar2 = (undefined4 *)(local_4 + -0x14);

    LVar1 = InterlockedDecrement((LONG *)(local_4 + -0x10));

    if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

      (**(code **)*puVar2)(1);

    }

  }

  return;

}





// --- FUN_0040d470 at 0x0040D470 (size: 36) ---


undefined4 * __thiscall FUN_0040d470(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_00795488;

  FUN_0040d410();

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040d4a0 at 0x0040D4A0 (size: 761) ---


undefined4 FUN_0040d4a0(int *param_1,undefined4 param_2,int param_3,undefined4 param_4)



{

  char cVar1;

  int iVar2;

  LONG LVar3;

  intptr_t iVar4;

  char *pcVar5;

  undefined4 *puVar6;

  char *local_154;

  char *local_150;

  undefined *local_14c;

  int local_148;

  int iStack_144;

  int local_140;

  intptr_t local_13c;

  undefined **local_138;

  undefined4 local_134;

  undefined4 local_130;

  int *local_12c;

  undefined **local_128;

  undefined4 local_124;

  undefined4 local_120;

  char **local_11c;

  uint local_118 [5];

  undefined1 local_104 [260];

  

  local_14c = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  FUN_0040c780(&local_14c,param_1);

  FUN_00401340(&DAT_00795504);

  FUN_0040d260(&local_140,&local_14c);

  local_148 = *param_1;

  InterlockedIncrement((LONG *)(local_148 + -0x10));

  FUN_0040c720(&local_148);

  local_13c = findfirst(local_140,local_118);

  iVar4 = local_13c;

  while (iVar4 != -1) {

    FUN_00401340(local_104);

    iVar2 = _stricmp(local_150,DAT_008377f0);

    if ((iVar2 != 0) && (iVar2 = _stricmp(local_150,DAT_008377f4), iVar2 != 0)) {

      local_11c = &local_150;

      local_128 = &PTR_FUN_0079548c;

      local_138 = &PTR_FUN_0079548c;

      local_12c = &local_148;

      local_124 = 0;

      local_120 = 0;

      local_134 = 0;

      local_130 = 0;

      cVar1 = FUN_0040b400(&local_128,&local_138);

      local_138 = &PTR_LAB_00795478;

      local_128 = &PTR_LAB_00795478;

      if (cVar1 != '\0') {

        local_154 = local_150;

        InterlockedIncrement((LONG *)(local_150 + -0x10));

        FUN_0040d260(&local_154,&local_14c);

        FUN_0040b720(&local_154);

        pcVar5 = local_154 + -0x14;

        LVar3 = InterlockedDecrement((LONG *)(local_154 + -0x10));

        if ((LVar3 == 0) && (pcVar5 != (char *)0x0)) {

          (*(code *)**(undefined4 **)pcVar5)(1);

        }

      }

      if (((local_118[0] >> 4 & 1) != 0) && ((param_3 != 0 || ((char)param_4 != '\0')))) {

        local_154 = local_150;

        InterlockedIncrement((LONG *)(local_150 + -0x10));

        FUN_0040d260(&local_154,&local_14c);

        if (param_3 != 0) {

          FUN_0040b720(&local_154);

        }

        if ((char)param_4 != '\0') {

          iStack_144 = local_148;

          InterlockedIncrement((LONG *)(local_148 + -0x10));

          FUN_0040d260(&iStack_144,&local_154);

          FUN_0040d4a0(&iStack_144,param_2,param_3,param_4);

          puVar6 = (undefined4 *)(iStack_144 + -0x14);

          LVar3 = InterlockedDecrement((LONG *)(iStack_144 + -0x10));

          if ((LVar3 == 0) && (puVar6 != (undefined4 *)0x0)) {

            (**(code **)*puVar6)(1);

          }

        }

        pcVar5 = local_154 + -0x14;

        LVar3 = InterlockedDecrement((LONG *)(local_154 + -0x10));

        if ((LVar3 == 0) && (pcVar5 != (char *)0x0)) {

          (*(code *)**(undefined4 **)pcVar5)(1);

        }

      }

    }

    pcVar5 = local_150 + -0x14;

    LVar3 = InterlockedDecrement((LONG *)(local_150 + -0x10));

    if ((LVar3 == 0) && (pcVar5 != (char *)0x0)) {

      (*(code *)**(undefined4 **)pcVar5)(1);

    }

    iVar4 = findnext(local_13c,local_118);

  }

  _findclose(local_13c);

  puVar6 = (undefined4 *)(local_148 + -0x14);

  LVar3 = InterlockedDecrement((LONG *)(local_148 + -0x10));

  if ((LVar3 == 0) && (puVar6 != (undefined4 *)0x0)) {

    (**(code **)*puVar6)(1);

  }

  LVar3 = InterlockedDecrement((LONG *)(local_140 + -0x10));

  if ((LVar3 == 0) && ((undefined4 *)(local_140 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(local_140 + -0x14))(1);

  }

  puVar6 = (undefined4 *)(local_14c + -0x14);

  LVar3 = InterlockedDecrement((LONG *)(local_14c + -0x10));

  if ((LVar3 == 0) && (puVar6 != (undefined4 *)0x0)) {

    (**(code **)*puVar6)(1);

  }

  return 1;

}





// --- FUN_0040d7a0 at 0x0040D7A0 (size: 111) ---


undefined4 FUN_0040d7a0(int *param_1)



{

  int iVar1;

  LONG LVar2;

  int local_4;

  

  FUN_00408fd0(&local_4,0);

  iVar1 = *param_1;

  if (iVar1 != local_4) {

    LVar2 = InterlockedDecrement((LONG *)(iVar1 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(iVar1 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(iVar1 + -0x14))(1);

    }

    *param_1 = local_4;

    InterlockedIncrement((LONG *)(local_4 + -0x10));

  }

  LVar2 = InterlockedDecrement((LONG *)(local_4 + -0x10));

  if ((LVar2 == 0) && ((undefined4 *)(local_4 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(local_4 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040d810 at 0x0040D810 (size: 95) ---


undefined4 * FUN_0040d810(undefined4 *param_1,undefined4 param_2)



{

  undefined *puVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined *local_4;

  

  local_4 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  FUN_0040d7a0(&local_4,param_2);

  puVar1 = local_4;

  *param_1 = local_4;

  InterlockedIncrement((LONG *)(local_4 + -0x10));

  puVar3 = (undefined4 *)(puVar1 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return param_1;

}





// --- FUN_0040d870 at 0x0040D870 (size: 409) ---


uint __thiscall FUN_0040d870(int *param_1,int *param_2,int *param_3)



{

  wchar_t *pwVar1;

  LONG LVar2;

  int *piVar3;

  wchar_t *pwVar4;

  size_t _Count;

  wchar_t *pwVar5;

  wchar_t *_Source;

  wchar_t *local_14;

  wchar_t *local_10;

  int local_c;

  int *local_8;

  int *local_4;

  

  piVar3 = (int *)0x0;

  local_c = 0;

  local_8 = (int *)0x0;

  local_4 = (int *)0x0;

  for (pwVar1 = wcsstr((wchar_t *)*param_1,(wchar_t *)*param_2); pwVar1 != (wchar_t *)0x0;

      pwVar1 = wcsstr(pwVar1 + *(int *)((wchar_t *)*param_2 + -2) + -1,(wchar_t *)*param_2)) {

    local_14 = pwVar1;

    if (piVar3 == local_4) {

      FUN_00660f50(piVar3,&local_14,&param_3,1,1);

    }

    else {

      if (piVar3 != (int *)0x0) {

        *piVar3 = (int)pwVar1;

      }

      local_8 = piVar3 + 1;

    }

    piVar3 = local_8;

  }

  local_14 = (wchar_t *)((int)piVar3 - local_c >> 2);

  if (local_14 == (wchar_t *)0x0) {

    if (local_c != 0) {

      FUN_004051c0(local_c,((int)local_4 - local_c >> 2) * 4);

    }

    return 0;

  }

  _Source = (wchar_t *)*param_1;

  local_10 = _Source + -10;

  FUN_004022d0((*(int *)(*param_3 + -4) - *(int *)(*param_2 + -4)) * (int)local_14 + -1 +

               *(int *)(_Source + -2));

  pwVar1 = (wchar_t *)*param_1;

  pwVar4 = (wchar_t *)0x0;

  pwVar5 = _Source + -10;

  if (local_14 != (wchar_t *)0x0) {

    do {

      _Count = *(int *)(local_c + (int)pwVar4 * 4) - (int)_Source >> 1;

      wcsncpy(pwVar1,_Source,_Count);

      wcscpy(pwVar1 + _Count,(wchar_t *)*param_3);

      pwVar1 = pwVar1 + _Count + *(int *)(*param_3 + -4) + -1;

      pwVar4 = (wchar_t *)((int)pwVar4 + 1);

      _Source = _Source + *(int *)(*param_2 + -4) + _Count + -1;

      pwVar5 = local_10;

    } while (pwVar4 < local_14);

  }

  wcscpy(pwVar1,_Source);

  LVar2 = InterlockedDecrement((LONG *)(pwVar5 + 2));

  if ((LVar2 == 0) && (pwVar5 != (wchar_t *)0x0)) {

    (*(code *)**(undefined4 **)pwVar5)(1);

  }

  if (local_c != 0) {

    FUN_004051c0(local_c,((int)local_4 - local_c >> 2) * 4);

  }

  return (uint)local_14;

}





// --- FUN_0040da10 at 0x0040DA10 (size: 281) ---


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



undefined4 FUN_0040da10(undefined4 param_1,char param_2)



{

  undefined4 *puVar1;

  

  if ((_DAT_008377ec & 1) == 0) {

    _DAT_008377ec = _DAT_008377ec | 1;

    puVar1 = (undefined4 *)thunk_FUN_005df0f5(0x24);

    if (puVar1 != (undefined4 *)0x0) {

      puVar1[1] = 1;

      *puVar1 = &PTR_LAB_007cae34;

      puVar1[4] = 1;

      puVar1[2] = 1;

      puVar1[3] = 0xffffffff;

      DAT_008377e8 = puVar1 + 5;

      *(undefined1 *)DAT_008377e8 = 0;

      puVar1[4] = 2;

      DAT_008377e8[-3] = 0x10;

    }

    *(undefined1 *)DAT_008377e8 = 0x5c;

    *(undefined1 *)((int)DAT_008377e8 + 1) = 0;

    _atexit((_func_4879 *)&LAB_00726bb0);

  }

  if ((_DAT_008377ec & 2) == 0) {

    _DAT_008377ec = _DAT_008377ec | 2;

    puVar1 = (undefined4 *)thunk_FUN_005df0f5(0x24);

    if (puVar1 != (undefined4 *)0x0) {

      puVar1[1] = 1;

      *puVar1 = &PTR_LAB_007cae34;

      puVar1[4] = 1;

      puVar1[2] = 1;

      puVar1[3] = 0xffffffff;

      DAT_008377e4 = puVar1 + 5;

      *(undefined1 *)DAT_008377e4 = 0;

      puVar1[4] = 2;

      DAT_008377e4[-3] = 0x10;

    }

    *(undefined1 *)DAT_008377e4 = 0x2f;

    *(undefined1 *)((int)DAT_008377e4 + 1) = 0;

    _atexit((_func_4879 *)&LAB_00726b80);

  }

  if (param_2 != '\0') {

    FUN_004053a0(&DAT_008377e4,&DAT_008377e8);

    return 1;

  }

  FUN_004053a0(&DAT_008377e8,&DAT_008377e4);

  return 1;

}





// --- FUN_0040db30 at 0x0040DB30 (size: 180) ---


undefined4 FUN_0040db30(void)



{

  DWORD DVar1;

  LONG LVar2;

  int local_408;

  int local_404;

  CHAR local_400 [1024];

  

  DVar1 = GetCurrentDirectoryA(0x400,local_400);

  if (DVar1 != 0) {

    FUN_00405000(local_400);

    FUN_00401340(&DAT_007954ac);

    FUN_00401340(&DAT_0079550c);

    FUN_004053a0(&local_404,&local_408);

    LVar2 = InterlockedDecrement((LONG *)(local_404 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(local_404 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(local_404 + -0x14))(1);

    }

    LVar2 = InterlockedDecrement((LONG *)(local_408 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(local_408 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(local_408 + -0x14))(1);

    }

    return 1;

  }

  return 0;

}





// --- thunk_FUN_0040da10 at 0x0040DBF0 (size: 5) ---


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



undefined4 thunk_FUN_0040da10(undefined4 param_1,char param_2)



{

  undefined4 *puVar1;

  

  if ((_DAT_008377ec & 1) == 0) {

    _DAT_008377ec = _DAT_008377ec | 1;

    puVar1 = (undefined4 *)thunk_FUN_005df0f5(0x24);

    if (puVar1 != (undefined4 *)0x0) {

      puVar1[1] = 1;

      *puVar1 = &PTR_LAB_007cae34;

      puVar1[4] = 1;

      puVar1[2] = 1;

      puVar1[3] = 0xffffffff;

      DAT_008377e8 = puVar1 + 5;

      *(undefined1 *)DAT_008377e8 = 0;

      puVar1[4] = 2;

      DAT_008377e8[-3] = 0x10;

    }

    *(undefined1 *)DAT_008377e8 = 0x5c;

    *(undefined1 *)((int)DAT_008377e8 + 1) = 0;

    _atexit((_func_4879 *)&LAB_00726bb0);

  }

  if ((_DAT_008377ec & 2) == 0) {

    _DAT_008377ec = _DAT_008377ec | 2;

    puVar1 = (undefined4 *)thunk_FUN_005df0f5(0x24);

    if (puVar1 != (undefined4 *)0x0) {

      puVar1[1] = 1;

      *puVar1 = &PTR_LAB_007cae34;

      puVar1[4] = 1;

      puVar1[2] = 1;

      puVar1[3] = 0xffffffff;

      DAT_008377e4 = puVar1 + 5;

      *(undefined1 *)DAT_008377e4 = 0;

      puVar1[4] = 2;

      DAT_008377e4[-3] = 0x10;

    }

    *(undefined1 *)DAT_008377e4 = 0x2f;

    *(undefined1 *)((int)DAT_008377e4 + 1) = 0;

    _atexit((_func_4879 *)&LAB_00726b80);

  }

  if (param_2 != '\0') {

    FUN_004053a0(&DAT_008377e4,&DAT_008377e8);

    return 1;

  }

  FUN_004053a0(&DAT_008377e8,&DAT_008377e4);

  return 1;

}





// --- FUN_0040dc00 at 0x0040DC00 (size: 595) ---


undefined1 FUN_0040dc00(undefined4 *param_1)



{

  int iVar1;

  LPCSTR pCVar2;

  char cVar3;

  DWORD DVar4;

  LONG LVar5;

  HANDLE hFindFile;

  undefined4 *puVar6;

  undefined *puVar7;

  LPCSTR *ppCVar8;

  int iVar9;

  undefined1 local_371;

  undefined *local_370;

  int local_36c;

  int local_368;

  LPCSTR local_364;

  undefined **local_360;

  int local_35c;

  undefined4 local_358;

  undefined4 local_354;

  int local_350;

  LPSTR local_34c;

  CHAR local_348 [260];

  CHAR local_244 [260];

  _WIN32_FIND_DATAA _Stack_140;

  

  local_371 = 0;

  DVar4 = GetFullPathNameA((LPCSTR)*param_1,0x104,local_348,&local_34c);

  if ((DVar4 == 0) ||

     (DVar4 = GetLongPathNameA(local_348,local_244,0x104), puVar7 = PTR_DAT_00818344, DVar4 == 0)) {

    return 0;

  }

  local_370 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  FUN_00401340(local_244);

  cVar3 = FUN_0040da10(&local_36c,0);

  if (cVar3 != '\0') {

    local_360 = &PTR_FUN_00795074;

    local_35c = 0;

    local_358 = 0;

    local_354 = 0;

    cVar3 = FUN_0040c2d0(&local_36c,0x2f,&local_360);

    iVar1 = local_35c;

    if (cVar3 != '\0') {

      FUN_00402070(local_35c);

      if (iVar1 != 0) {

        for (iVar1 = *(int *)(iVar1 + 4); iVar1 != 0; iVar1 = *(int *)(iVar1 + 4)) {

          FUN_00401340(&DAT_007954ac);

          ppCVar8 = &local_364;

          iVar9 = iVar1;

          FUN_0040bbc0(&local_350,&local_368);

          FUN_0040bbc0(ppCVar8,iVar9);

          puVar6 = (undefined4 *)(local_350 + -0x14);

          LVar5 = InterlockedDecrement((LONG *)(local_350 + -0x10));

          if ((LVar5 == 0) && (puVar6 != (undefined4 *)0x0)) {

            (**(code **)*puVar6)(1);

          }

          puVar6 = (undefined4 *)(local_368 + -0x14);

          LVar5 = InterlockedDecrement((LONG *)(local_368 + -0x10));

          if ((LVar5 == 0) && (puVar6 != (undefined4 *)0x0)) {

            (**(code **)*puVar6)(1);

          }

          pCVar2 = local_364;

          hFindFile = FindFirstFileA(local_364,&_Stack_140);

          if (hFindFile == (HANDLE)0xffffffff) {

            LVar5 = InterlockedDecrement((LONG *)(pCVar2 + -0x10));

            if ((LVar5 == 0) && (pCVar2 + -0x14 != (LPCSTR)0x0)) {

              (*(code *)**(undefined4 **)(pCVar2 + -0x14))(1);

            }

            goto LAB_0040ddd5;

          }

          FUN_00406500(&local_370,&DAT_00795510,_Stack_140.cFileName);

          FindClose(hFindFile);

          LVar5 = InterlockedDecrement((LONG *)(pCVar2 + -0x10));

          if ((LVar5 == 0) && (pCVar2 + -0x14 != (LPCSTR)0x0)) {

            (*(code *)**(undefined4 **)(pCVar2 + -0x14))(1);

          }

          if (iVar1 == 0) break;

        }

      }

      FUN_00401700(&local_370);

      local_371 = 1;

    }

LAB_0040ddd5:

    local_360 = &PTR_FUN_00795074;

    FUN_00405210();

    puVar7 = local_370;

  }

  LVar5 = InterlockedDecrement((LONG *)(local_36c + -0x10));

  if ((LVar5 == 0) && ((undefined4 *)(local_36c + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(local_36c + -0x14))(1);

  }

  LVar5 = InterlockedDecrement((LONG *)(puVar7 + -0x10));

  if ((LVar5 == 0) && ((undefined4 *)(puVar7 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(puVar7 + -0x14))(1);

  }

  return local_371;

}





// --- FUN_0040de60 at 0x0040DE60 (size: 73) ---


undefined4 FUN_0040de60(void)



{

  LONG LVar1;

  int local_4;

  

  FUN_00401340(&DAT_00795508);

  FUN_004053a0(&local_4,&PTR_DAT_00818344);

  LVar1 = InterlockedDecrement((LONG *)(local_4 + -0x10));

  if ((LVar1 == 0) && ((undefined4 *)(local_4 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(local_4 + -0x14))(1);

  }

  return 1;

}





// --- FUN_0040deb0 at 0x0040DEB0 (size: 86) ---


undefined4 FUN_0040deb0(int *param_1,undefined4 param_2)



{

  uint uVar1;

  uint uVar2;

  undefined4 uVar3;

  char cVar4;

  

  uVar3 = param_2;

  FUN_0040da10(param_1,param_2);

  uVar2 = *(uint *)(*param_1 + -4);

  cVar4 = (-((char)uVar3 != '\0') & 0x2dU) + 0x2f;

  if (1 < uVar2) {

    uVar1 = uVar2 - 2;

    if (uVar2 <= uVar1) {

      uVar1 = uVar2 - 1;

    }

    if (*(char *)(*param_1 + uVar1) != cVar4) {

      param_2 = CONCAT31(param_2._1_3_,cVar4);

      FUN_00404ef0(&param_2,1);

    }

  }

  return 1;

}





// --- thunk_FUN_0040deb0 at 0x0040DF10 (size: 5) ---


undefined4 thunk_FUN_0040deb0(int *param_1,undefined4 param_2)



{

  uint uVar1;

  uint uVar2;

  undefined4 uVar3;

  char cVar4;

  

  uVar3 = param_2;

  FUN_0040da10(param_1,param_2);

  uVar2 = *(uint *)(*param_1 + -4);

  cVar4 = (-((char)uVar3 != '\0') & 0x2dU) + 0x2f;

  if (1 < uVar2) {

    uVar1 = uVar2 - 2;

    if (uVar2 <= uVar1) {

      uVar1 = uVar2 - 1;

    }

    if (*(char *)(*param_1 + uVar1) != cVar4) {

      param_2 = CONCAT31(param_2._1_3_,cVar4);

      FUN_00404ef0(&param_2,1);

    }

  }

  return 1;

}





// --- FUN_0040df20 at 0x0040DF20 (size: 492) ---


undefined4 FUN_0040df20(int *param_1)



{

  uint uVar1;

  uint uVar2;

  int *piVar3;

  char *lpPathName;

  char cVar4;

  LONG LVar5;

  int iVar6;

  BOOL BVar7;

  undefined4 *puVar8;

  int local_18;

  char *local_14;

  undefined **local_10;

  int *local_c;

  undefined4 local_8;

  undefined4 local_4;

  

  local_18 = *param_1;

  InterlockedIncrement((LONG *)(local_18 + -0x10));

  FUN_0040da10(&local_18,0);

  uVar2 = *(uint *)(local_18 + -4);

  if (1 < uVar2) {

    uVar1 = uVar2 - 2;

    if (uVar2 <= uVar1) {

      uVar1 = uVar2 - 1;

    }

    if (*(char *)(uVar1 + local_18) != '/') {

      param_1 = (int *)CONCAT31(param_1._1_3_,0x2f);

      FUN_00404ef0(&param_1,1);

    }

  }

  local_10 = &PTR_FUN_00795074;

  local_c = (int *)0x0;

  local_8 = 0;

  local_4 = 0;

  cVar4 = FUN_0040c2d0(&local_18,0x2f,&local_10);

  piVar3 = local_c;

  lpPathName = PTR_DAT_00818344;

  if (cVar4 == '\0') {

    local_10 = &PTR_FUN_00795074;

    FUN_00405210();

    puVar8 = (undefined4 *)(local_18 + -0x14);

    LVar5 = InterlockedDecrement((LONG *)(local_18 + -0x10));

    if ((LVar5 == 0) && (puVar8 != (undefined4 *)0x0)) {

      (**(code **)*puVar8)(1);

    }

    return 0;

  }

  local_14 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  while( true ) {

    if (piVar3 == (int *)0x0) {

      LVar5 = InterlockedDecrement((LONG *)(lpPathName + -0x10));

      if ((LVar5 == 0) && (lpPathName + -0x14 != (char *)0x0)) {

        (*(code *)**(undefined4 **)(lpPathName + -0x14))(1);

      }

      local_10 = &PTR_FUN_00795074;

      FUN_00405210();

      puVar8 = (undefined4 *)(local_18 + -0x14);

      LVar5 = InterlockedDecrement((LONG *)(local_18 + -0x10));

      if ((LVar5 == 0) && (puVar8 != (undefined4 *)0x0)) {

        (**(code **)*puVar8)(1);

      }

      return 1;

    }

    iVar6 = *(int *)(*piVar3 + -4);

    if (iVar6 != 1) {

      FUN_00404ef0(*piVar3,iVar6 + -1);

    }

    param_1 = (int *)CONCAT31(param_1._1_3_,0x2f);

    FUN_00404ef0(&param_1,1);

    lpPathName = local_14;

    iVar6 = _access(local_14,0);

    if ((iVar6 != 0) &&

       (BVar7 = CreateDirectoryA(lpPathName,(LPSECURITY_ATTRIBUTES)0x0), BVar7 == 0)) break;

    piVar3 = (int *)piVar3[1];

  }

  LVar5 = InterlockedDecrement((LONG *)(lpPathName + -0x10));

  if ((LVar5 == 0) && (lpPathName + -0x14 != (char *)0x0)) {

    (*(code *)**(undefined4 **)(lpPathName + -0x14))(1);

  }

  local_10 = &PTR_FUN_00795074;

  FUN_00405210();

  puVar8 = (undefined4 *)(local_18 + -0x14);

  LVar5 = InterlockedDecrement((LONG *)(local_18 + -0x10));

  if ((LVar5 == 0) && (puVar8 != (undefined4 *)0x0)) {

    (**(code **)*puVar8)(1);

  }

  return 0;

}





// --- thunk_FUN_0040df20 at 0x0040E110 (size: 5) ---


undefined4 thunk_FUN_0040df20(int *param_1)



{

  uint uVar1;

  uint uVar2;

  int *piVar3;

  char *lpPathName;

  char cVar4;

  LONG LVar5;

  int iVar6;

  BOOL BVar7;

  undefined4 *puVar8;

  int iStack_18;

  char *pcStack_14;

  undefined **ppuStack_10;

  int *piStack_c;

  undefined4 uStack_8;

  undefined4 uStack_4;

  

  iStack_18 = *param_1;

  InterlockedIncrement((LONG *)(iStack_18 + -0x10));

  FUN_0040da10(&iStack_18,0);

  uVar2 = *(uint *)(iStack_18 + -4);

  if (1 < uVar2) {

    uVar1 = uVar2 - 2;

    if (uVar2 <= uVar1) {

      uVar1 = uVar2 - 1;

    }

    if (*(char *)(uVar1 + iStack_18) != '/') {

      param_1 = (int *)CONCAT31(param_1._1_3_,0x2f);

      FUN_00404ef0(&param_1,1);

    }

  }

  ppuStack_10 = &PTR_FUN_00795074;

  piStack_c = (int *)0x0;

  uStack_8 = 0;

  uStack_4 = 0;

  cVar4 = FUN_0040c2d0(&iStack_18,0x2f,&ppuStack_10);

  piVar3 = piStack_c;

  lpPathName = PTR_DAT_00818344;

  if (cVar4 == '\0') {

    ppuStack_10 = &PTR_FUN_00795074;

    FUN_00405210();

    puVar8 = (undefined4 *)(iStack_18 + -0x14);

    LVar5 = InterlockedDecrement((LONG *)(iStack_18 + -0x10));

    if ((LVar5 == 0) && (puVar8 != (undefined4 *)0x0)) {

      (**(code **)*puVar8)(1);

    }

    return 0;

  }

  pcStack_14 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  while( true ) {

    if (piVar3 == (int *)0x0) {

      LVar5 = InterlockedDecrement((LONG *)(lpPathName + -0x10));

      if ((LVar5 == 0) && (lpPathName + -0x14 != (char *)0x0)) {

        (*(code *)**(undefined4 **)(lpPathName + -0x14))(1);

      }

      ppuStack_10 = &PTR_FUN_00795074;

      FUN_00405210();

      puVar8 = (undefined4 *)(iStack_18 + -0x14);

      LVar5 = InterlockedDecrement((LONG *)(iStack_18 + -0x10));

      if ((LVar5 == 0) && (puVar8 != (undefined4 *)0x0)) {

        (**(code **)*puVar8)(1);

      }

      return 1;

    }

    iVar6 = *(int *)(*piVar3 + -4);

    if (iVar6 != 1) {

      FUN_00404ef0(*piVar3,iVar6 + -1);

    }

    param_1 = (int *)CONCAT31(param_1._1_3_,0x2f);

    FUN_00404ef0(&param_1,1);

    lpPathName = pcStack_14;

    iVar6 = _access(pcStack_14,0);

    if ((iVar6 != 0) &&

       (BVar7 = CreateDirectoryA(lpPathName,(LPSECURITY_ATTRIBUTES)0x0), BVar7 == 0)) break;

    piVar3 = (int *)piVar3[1];

  }

  LVar5 = InterlockedDecrement((LONG *)(lpPathName + -0x10));

  if ((LVar5 == 0) && (lpPathName + -0x14 != (char *)0x0)) {

    (*(code *)**(undefined4 **)(lpPathName + -0x14))(1);

  }

  ppuStack_10 = &PTR_FUN_00795074;

  FUN_00405210();

  puVar8 = (undefined4 *)(iStack_18 + -0x14);

  LVar5 = InterlockedDecrement((LONG *)(iStack_18 + -0x10));

  if ((LVar5 == 0) && (puVar8 != (undefined4 *)0x0)) {

    (**(code **)*puVar8)(1);

  }

  return 0;

}





// --- FUN_0040e120 at 0x0040E120 (size: 119) ---


bool FUN_0040e120(undefined4 *param_1,undefined4 *param_2,LPBYTE param_3,DWORD param_4,HKEY param_5)



{

  LSTATUS LVar1;

  bool bVar2;

  HKEY local_4;

  

  local_4 = (HKEY)0x0;

  LVar1 = RegOpenKeyExA(param_5,(LPCSTR)*param_1,0,0x20019,&local_4);

  bVar2 = false;

  if (LVar1 == 0) {

    LVar1 = RegQueryValueExA(local_4,(LPCSTR)*param_2,(LPDWORD)0x0,(LPDWORD)&param_1,param_3,

                             &param_4);

    bVar2 = LVar1 == 0;

  }

  if (local_4 != (HKEY)0x0) {

    RegCloseKey(local_4);

  }

  return bVar2;

}





// --- FUN_0040e1a0 at 0x0040E1A0 (size: 122) ---


bool FUN_0040e1a0(undefined4 *param_1)



{

  int iVar1;

  undefined4 unaff_EBX;

  bool bVar2;

  undefined4 in_stack_00000014;

  HKEY hKey;

  undefined4 uStack_10;

  undefined4 *puStack_c;

  undefined4 local_4;

  

  puStack_c = &local_4;

  uStack_10 = 0x20019;

  hKey = (HKEY)*param_1;

  local_4 = 0;

  iVar1 = (*(code *)PTR_FUN_00837350)(in_stack_00000014,hKey,0);

  bVar2 = false;

  if (iVar1 == 0) {

    iVar1 = (*(code *)PTR_FUN_00837354)(hKey,*puStack_c,0,&uStack_10,unaff_EBX,&local_4);

    bVar2 = iVar1 == 0;

  }

  if (hKey != (HKEY)0x0) {

    RegCloseKey(hKey);

  }

  return bVar2;

}





// --- FUN_0040e220 at 0x0040E220 (size: 94) ---


bool FUN_0040e220(undefined4 *param_1,undefined4 *param_2,HKEY param_3)



{

  LSTATUS LVar1;

  bool bVar2;

  HKEY local_4;

  

  local_4 = (HKEY)0x0;

  LVar1 = RegOpenKeyExA(param_3,(LPCSTR)*param_1,0,0x20006,&local_4);

  bVar2 = false;

  if (LVar1 == 0) {

    LVar1 = RegDeleteValueA(local_4,(LPCSTR)*param_2);

    bVar2 = LVar1 == 0;

  }

  if (local_4 != (HKEY)0x0) {

    RegCloseKey(local_4);

  }

  return bVar2;

}





// --- FUN_0040e280 at 0x0040E280 (size: 82) ---


undefined1 FUN_0040e280(undefined4 param_1,undefined4 param_2,undefined4 param_3,undefined4 param_4)



{

  char cVar1;

  undefined1 local_800 [2048];

  

  cVar1 = FUN_0040e120(param_1,param_2,local_800,0x800,param_4);

  if (cVar1 == '\0') {

    return 0;

  }

  FUN_00405000(local_800);

  return 1;

}





// --- FUN_0040e2e0 at 0x0040E2E0 (size: 89) ---


/* WARNING: Function: __chkstk replaced with injection: alloca_probe */



undefined1 FUN_0040e2e0(undefined4 param_1,undefined4 param_2,undefined4 param_3,undefined4 param_4)



{

  char cVar1;

  undefined1 local_1000 [4092];

  undefined4 uStack_4;

  

  uStack_4 = 0x40e2ea;

  cVar1 = FUN_0040e1a0(param_1,param_2,local_1000,0x800,param_4);

  if (cVar1 == '\0') {

    return 0;

  }

  FUN_00407e40(local_1000);

  return 1;

}





// --- FUN_0040e340 at 0x0040E340 (size: 87) ---


uint __thiscall FUN_0040e340(int *param_1,int param_2)



{

  uint uVar1;

  int *piVar2;

  uint uVar3;

  

  uVar1 = 0;

  if (param_1[2] != 0) {

    piVar2 = (int *)*param_1;

    do {

      if (*piVar2 == param_2) {

        *(undefined4 *)(param_2 + 4) = 0;

        if (uVar1 < (uint)param_1[2]) {

          uVar3 = param_1[2] - 1;

          param_1[2] = uVar3;

          if (uVar1 != uVar3) {

            *(undefined4 *)(*param_1 + uVar1 * 4) = *(undefined4 *)(*param_1 + uVar3 * 4);

            uVar1 = param_1[2];

            *(undefined4 *)(*param_1 + uVar1 * 4) = 0;

          }

        }

        return CONCAT31((int3)(uVar1 >> 8),1);

      }

      uVar1 = uVar1 + 1;

      piVar2 = piVar2 + 1;

    } while (uVar1 < (uint)param_1[2]);

  }

  return uVar1 & 0xffffff00;

}





// --- FUN_0040e3a0 at 0x0040E3A0 (size: 55) ---


void FUN_0040e3a0(void)



{

  uint uVar1;

  

  if (DAT_008377f8 == '\0') {

    uVar1 = 0;

    DAT_008377f8 = '\x01';

    if (DAT_00837804 != 0) {

      do {

        (**(code **)(**(int **)(DAT_008377fc + uVar1 * 4) + 8))();

        uVar1 = uVar1 + 1;

      } while (uVar1 < DAT_00837804);

    }

  }

  return;

}





// --- FUN_0040e3e0 at 0x0040E3E0 (size: 61) ---


void __fastcall FUN_0040e3e0(int *param_1)



{

  int iVar1;

  uint uVar2;

  

  uVar2 = 0;

  if (param_1[2] != 0) {

    do {

      iVar1 = uVar2 * 4;

      uVar2 = uVar2 + 1;

      *(undefined4 *)(*(int *)(*param_1 + iVar1) + 4) = 0;

    } while (uVar2 < (uint)param_1[2]);

  }

  param_1[2] = 0;

  if ((param_1[1] & 0x80000000U) == 0x80000000) {

    operator_delete__((void *)*param_1);

  }

  return;

}





// --- FUN_0040e420 at 0x0040E420 (size: 48) ---


void __fastcall FUN_0040e420(undefined4 *param_1)



{

  *param_1 = &PTR_FUN_00795540;

  FUN_0040e340(param_1);

  *param_1 = &PTR_FUN_00795538;

  if (param_1[1] != 0) {

    FUN_0040e340(param_1);

    param_1[1] = 0;

  }

  return;

}





// --- FUN_0040e450 at 0x0040E450 (size: 51) ---


undefined4 * __thiscall FUN_0040e450(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_00795538;

  if (param_1[1] != 0) {

    FUN_0040e340(param_1);

    param_1[1] = 0;

  }

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040e490 at 0x0040E490 (size: 68) ---


undefined4 * __thiscall FUN_0040e490(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_00795540;

  FUN_0040e340(param_1);

  *param_1 = &PTR_FUN_00795538;

  if (param_1[1] != 0) {

    FUN_0040e340(param_1);

    param_1[1] = 0;

  }

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040e4e0 at 0x0040E4E0 (size: 84) ---


undefined4 __thiscall FUN_0040e4e0(int *param_1,int *param_2)



{

  char cVar1;

  undefined4 uVar2;

  

  if (param_2[1] != 0) {

    return 0;

  }

  if ((param_1[1] & 0x7fffffffU) <= (uint)param_1[2]) {

    uVar2 = FUN_004077f0((param_1[1] & 0x7fffffffU) + 1);

    cVar1 = FUN_00408220(uVar2);

    if (cVar1 == '\0') goto LAB_0040e525;

  }

  *(int **)(*param_1 + param_1[2] * 4) = param_2;

  param_1[2] = param_1[2] + 1;

LAB_0040e525:

  (**(code **)(*param_2 + 4))(param_1);

  return 1;

}





// --- FUN_0040e540 at 0x0040E540 (size: 31) ---


undefined4 * __fastcall FUN_0040e540(undefined4 *param_1)



{

  param_1[1] = 0;

  *param_1 = &PTR_FUN_00795540;

  FUN_0040e4e0(param_1);

  return param_1;

}





// --- FUN_0040e560 at 0x0040E560 (size: 101) ---


undefined8 FUN_0040e560(void)



{

  uint uVar1;

  uint uVar2;

  LONG LVar3;

  uint uVar4;

  uint uVar5;

  uint uVar6;

  undefined8 uVar7;

  

  uVar4 = DAT_00837814;

  uVar6 = DAT_00837810;

  LVar3 = InterlockedIncrement((LONG *)&DAT_008183c0);

  uVar1 = DAT_00837810;

  uVar2 = DAT_00837814;

  if ((LVar3 == 0) && (uVar5 = 0, uVar1 = uVar6, uVar2 = uVar4, DAT_00837820 != 0)) {

    do {

      (**(code **)(**(int **)(DAT_00837818 + uVar5 * 4) + 0x10))();

      uVar7 = __allshl();

      uVar5 = uVar5 + 1;

      uVar6 = uVar6 | (uint)uVar7;

      uVar4 = uVar4 | (uint)((ulonglong)uVar7 >> 0x20);

      uVar1 = uVar6;

      uVar2 = uVar4;

    } while (uVar5 < DAT_00837820);

  }

  DAT_00837814 = uVar2;

  DAT_00837810 = uVar1;

  return CONCAT44(uVar4,uVar6);

}





// --- FUN_0040e5d0 at 0x0040E5D0 (size: 80) ---


void FUN_0040e5d0(void)



{

  int iVar1;

  LONG LVar2;

  uint uVar3;

  uint uVar4;

  

  LVar2 = InterlockedDecrement((LONG *)&DAT_008183c0);

  if ((LVar2 < 0) && (uVar4 = 0, DAT_00837820 != 0)) {

    do {

      iVar1 = **(int **)(DAT_00837818 + uVar4 * 4);

      uVar3 = __aullshr();

      (**(code **)(iVar1 + 0x14))(uVar3 & 0xffffff01);

      uVar4 = uVar4 + 1;

    } while (uVar4 < DAT_00837820);

  }

  return;

}





// --- FUN_0040e620 at 0x0040E620 (size: 101) ---


undefined8 FUN_0040e620(void)



{

  uint uVar1;

  uint uVar2;

  LONG LVar3;

  uint uVar4;

  uint uVar5;

  uint uVar6;

  undefined8 uVar7;

  

  uVar4 = DAT_0083780c;

  uVar6 = DAT_00837808;

  LVar3 = InterlockedIncrement((LONG *)&DAT_008183bc);

  uVar1 = DAT_00837808;

  uVar2 = DAT_0083780c;

  if ((LVar3 == 0) && (uVar5 = 0, uVar1 = uVar6, uVar2 = uVar4, DAT_00837820 != 0)) {

    do {

      (**(code **)(**(int **)(DAT_00837818 + uVar5 * 4) + 0x18))();

      uVar7 = __allshl();

      uVar5 = uVar5 + 1;

      uVar6 = uVar6 | (uint)uVar7;

      uVar4 = uVar4 | (uint)((ulonglong)uVar7 >> 0x20);

      uVar1 = uVar6;

      uVar2 = uVar4;

    } while (uVar5 < DAT_00837820);

  }

  DAT_0083780c = uVar2;

  DAT_00837808 = uVar1;

  return CONCAT44(uVar4,uVar6);

}





// --- FUN_0040e690 at 0x0040E690 (size: 80) ---


void FUN_0040e690(void)



{

  int iVar1;

  LONG LVar2;

  uint uVar3;

  uint uVar4;

  

  LVar2 = InterlockedDecrement((LONG *)&DAT_008183bc);

  if ((LVar2 < 0) && (uVar4 = 0, DAT_00837820 != 0)) {

    do {

      iVar1 = **(int **)(DAT_00837818 + uVar4 * 4);

      uVar3 = __aullshr();

      (**(code **)(iVar1 + 0x1c))(uVar3 & 0xffffff01);

      uVar4 = uVar4 + 1;

    } while (uVar4 < DAT_00837820);

  }

  return;

}





// --- FUN_0040e6e0 at 0x0040E6E0 (size: 48) ---


void __fastcall FUN_0040e6e0(undefined4 *param_1)



{

  *param_1 = &PTR_FUN_0079554c;

  FUN_0040e340(param_1);

  *param_1 = &PTR_FUN_00795538;

  if (param_1[1] != 0) {

    FUN_0040e340(param_1);

    param_1[1] = 0;

  }

  return;

}





// --- FUN_0040e740 at 0x0040E740 (size: 68) ---


undefined4 * __thiscall FUN_0040e740(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_0079554c;

  FUN_0040e340(param_1);

  *param_1 = &PTR_FUN_00795538;

  if (param_1[1] != 0) {

    FUN_0040e340(param_1);

    param_1[1] = 0;

  }

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040e790 at 0x0040E790 (size: 31) ---


undefined4 * __fastcall FUN_0040e790(undefined4 *param_1)



{

  param_1[1] = 0;

  *param_1 = &PTR_FUN_0079554c;

  FUN_0040e4e0(param_1);

  return param_1;

}





// --- FUN_0040e7b0 at 0x0040E7B0 (size: 24) ---


void __fastcall FUN_0040e7b0(undefined4 *param_1)



{

  CloseHandle((HANDLE)param_1[2]);

  CloseHandle((HANDLE)*param_1);

  return;

}





// --- FUN_0040e7d0 at 0x0040E7D0 (size: 165) ---


undefined4 * __thiscall FUN_0040e7d0(undefined4 *param_1,int param_2)



{

  undefined4 *puVar1;

  HANDLE pvVar2;

  BOOL BVar3;

  DWORD DVar4;

  undefined4 uVar5;

  HMODULE pHVar6;

  undefined4 *local_4;

  

  local_4 = param_1;

  puVar1 = GetCurrentProcess();

  local_4 = puVar1;

  pvVar2 = GetCurrentProcess();

  BVar3 = DuplicateHandle(pvVar2,puVar1,pvVar2,&local_4,0,1,2);

  if (BVar3 != 0) {

    puVar1 = local_4;

  }

  *param_1 = puVar1;

  DVar4 = GetCurrentThreadId();

  param_1[1] = DVar4;

  puVar1 = GetCurrentThread();

  local_4 = puVar1;

  pvVar2 = GetCurrentProcess();

  BVar3 = DuplicateHandle(pvVar2,puVar1,pvVar2,&local_4,0,1,2);

  if (BVar3 != 0) {

    puVar1 = local_4;

  }

  param_1[2] = puVar1;

  if ((param_2 != 0) && (*(int *)(param_2 + 4) != 0)) {

    uVar5 = FUN_00411120();

    param_1[3] = uVar5;

    return param_1;

  }

  pHVar6 = GetModuleHandleA((LPCSTR)0x0);

  param_1[3] = pHVar6;

  return param_1;

}





// --- FUN_0040e880 at 0x0040E880 (size: 93) ---


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



void FUN_0040e880(void)



{

  if (DAT_0083782c != (HMODULE)0x0) {

    _DAT_00837830 = 0;

    _DAT_00837834 = 0;

    _DAT_00837838 = 0;

    _DAT_0083783c = 0;

    _DAT_00837840 = 0;

    _DAT_00837844 = 0;

    _DAT_00837848 = 0;

    _DAT_0083784c = 0;

    _DAT_00837850 = 0;

    _DAT_00837854 = 0;

    _DAT_00837858 = 0;

    FreeLibrary(DAT_0083782c);

    DAT_0083782c = (HMODULE)0x0;

  }

  return;

}





// --- FUN_0040e900 at 0x0040E900 (size: 1) ---


void FUN_0040e900(void)



{

  return;

}





// --- FUN_0040e910 at 0x0040E910 (size: 231) ---


/* WARNING: Function: __chkstk replaced with injection: alloca_probe */



int __thiscall FUN_0040e910(int param_1,undefined4 param_2,undefined4 param_3,char *param_4)



{

  char cVar1;

  char *pcVar2;

  int iVar3;

  uint uVar4;

  int local_1004;

  char local_1000 [4092];

  uint uStack_4;

  

  uStack_4 = 0x40e91a;

  local_1004 = 2;

  if (*(int *)(param_1 + 0x14) == 0) {

    return 2;

  }

  strncpy(local_1000,param_4,0xfff);

  pcVar2 = local_1000;

  uStack_4 = uStack_4 & 0xffffff;

  do {

    cVar1 = *pcVar2;

    pcVar2 = pcVar2 + 1;

  } while (cVar1 != '\0');

  iVar3 = (int)pcVar2 - (int)(local_1000 + 1);

  if (local_1000[iVar3 + -1] != '\n') {

    if (iVar3 == 0xfff) {

      iVar3 = 0xffe;

    }

    local_1000[iVar3] = '\n';

    local_1000[iVar3 + 1] = '\0';

  }

  uVar4 = 0;

  if (*(int *)(param_1 + 0x14) == 0) {

    return 2;

  }

  do {

    iVar3 = (**(code **)(**(int **)(*(int *)(param_1 + 0xc) + uVar4 * 4) + 4))

                      (param_2,param_3,local_1000);

    if (((-1 < iVar3) && (iVar3 < 2)) && (local_1004 != 0)) {

      local_1004 = iVar3;

    }

    uVar4 = uVar4 + 1;

  } while (uVar4 < *(uint *)(param_1 + 0x14));

  return local_1004;

}





// --- FUN_0040ea40 at 0x0040EA40 (size: 64) ---


undefined4 * __thiscall FUN_0040ea40(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_007955bc;

  if ((undefined4 *)param_1[0x18] != param_1 + 1) {

    operator_delete__((undefined4 *)param_1[0x18]);

  }

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040ea80 at 0x0040EA80 (size: 73) ---


undefined4 __fastcall FUN_0040ea80(int param_1)



{

  undefined4 *puVar1;

  

  if (*(int *)(param_1 + 0xa4) == 0) {

    puVar1 = (undefined4 *)FUN_005df0f5(8);

    if (puVar1 == (undefined4 *)0x0) {

      puVar1 = (undefined4 *)0x0;

    }

    else {

      puVar1[1] = 1;

      *puVar1 = &PTR_FUN_007955a0;

    }

    *(undefined4 **)(param_1 + 0xa4) = puVar1;

  }

  InterlockedIncrement((LONG *)(*(int *)(param_1 + 0xa4) + 4));

  return *(undefined4 *)(param_1 + 0xa4);

}





// --- FUN_0040ead0 at 0x0040EAD0 (size: 73) ---


undefined4 __fastcall FUN_0040ead0(int param_1)



{

  undefined4 *puVar1;

  

  if (*(int *)(param_1 + 0xa8) == 0) {

    puVar1 = (undefined4 *)FUN_005df0f5(8);

    if (puVar1 == (undefined4 *)0x0) {

      puVar1 = (undefined4 *)0x0;

    }

    else {

      puVar1[1] = 1;

      *puVar1 = &PTR_FUN_007955b0;

    }

    *(undefined4 **)(param_1 + 0xa8) = puVar1;

  }

  InterlockedIncrement((LONG *)(*(int *)(param_1 + 0xa8) + 4));

  return *(undefined4 *)(param_1 + 0xa8);

}





// --- FUN_0040eb20 at 0x0040EB20 (size: 20) ---


undefined4 FUN_0040eb20(int param_1)



{

  undefined4 uVar1;

  

  if (param_1 != 0) {

    uVar1 = FUN_0040a980();

    return uVar1;

  }

  return 0;

}





// --- FUN_0040eb40 at 0x0040EB40 (size: 22) ---


undefined4 FUN_0040eb40(void)



{

  undefined4 uVar1;

  

  if (DAT_008378d9 == '\0') {

    return 0;

  }

  uVar1 = FUN_0040ea80();

  return uVar1;

}





// --- FUN_0040eb60 at 0x0040EB60 (size: 22) ---


undefined4 FUN_0040eb60(void)



{

  undefined4 uVar1;

  

  if (DAT_008378d9 == '\0') {

    return 0;

  }

  uVar1 = FUN_0040ead0();

  return uVar1;

}





// --- FUN_0040eb80 at 0x0040EB80 (size: 292) ---


/* WARNING: Function: __chkstk replaced with injection: alloca_probe */



int __thiscall FUN_0040eb80(int *param_1,int param_2,int param_3)



{

  undefined4 uVar1;

  LONG LVar2;

  HANDLE pvVar3;

  DWORD DVar4;

  int iVar5;

  undefined4 *puVar6;

  int local_1004;

  char local_1000 [4092];

  undefined4 uStack_4;

  

  uStack_4 = 0x40eb8a;

  if (param_1[1] != 0) {

LAB_0040ec70:

    iVar5 = param_1[2];

    puVar6 = (undefined4 *)(param_3 + -0x14);

    LVar2 = InterlockedDecrement((LONG *)(param_3 + -0x10));

    if ((LVar2 == 0) && (puVar6 != (undefined4 *)0x0)) {

      (**(code **)*puVar6)(1);

    }

    return iVar5;

  }

  if (*(int *)(param_3 + -4) != 1) {

    FUN_00402070(&param_3);

  }

  if (*(int *)(*param_1 + -4) == 1) {

    uVar1 = FUN_0040c230(&local_1004);

    FUN_00402070(uVar1);

    LVar2 = InterlockedDecrement((LONG *)(local_1004 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(local_1004 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(local_1004 + -0x14))(1);

    }

    thunk_FUN_0040c720(param_1);

  }

  iVar5 = param_2;

  if (param_2 == 0) {

    iVar5 = 1;

  }

  do {

    sprintf(local_1000,"%s_%d",*param_1,iVar5);

    SetLastError(0);

    pvVar3 = CreateMutexA((LPSECURITY_ATTRIBUTES)0x0,0,local_1000);

    param_1[1] = (int)pvVar3;

    if (pvVar3 != (HANDLE)0x0) {

      DVar4 = GetLastError();

      if (DVar4 != 0xb7) {

        param_1[2] = iVar5;

        goto LAB_0040ec70;

      }

      CloseHandle((HANDLE)param_1[1]);

      if (param_2 != 0) goto LAB_0040ec70;

    }

    iVar5 = iVar5 + 1;

  } while( true );

}





// --- FUN_0040ecb0 at 0x0040ECB0 (size: 86) ---


int * __thiscall FUN_0040ecb0(int *param_1,byte param_2)



{

  LONG LVar1;

  undefined4 *puVar2;

  

  if ((HANDLE)param_1[1] != (HANDLE)0x0) {

    CloseHandle((HANDLE)param_1[1]);

    param_1[1] = 0;

    param_1[2] = 0;

  }

  puVar2 = (undefined4 *)(*param_1 + -0x14);

  LVar1 = InterlockedDecrement((LONG *)(*param_1 + -0x10));

  if ((LVar1 == 0) && (puVar2 != (undefined4 *)0x0)) {

    (**(code **)*puVar2)(1);

  }

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040ed10 at 0x0040ED10 (size: 158) ---


bool __thiscall FUN_0040ed10(int param_1,undefined4 *param_2)



{

  int iVar1;

  FILE *pFVar2;

  

  if (*(int *)((char *)*param_2 + -4) == 1) {

    return false;

  }

  if (*(int *)(param_1 + 8) != 0) {

    iVar1 = _stricmp(*(char **)(param_1 + 0x10),(char *)*param_2);

    if (iVar1 == 0) {

      return true;

    }

    fclose(*(FILE **)(param_1 + 8));

    if (*(int *)(param_1 + 0x14) != 0) {

      FUN_0040ecb0(1);

    }

    *(undefined4 *)(param_1 + 0x14) = 0;

  }

  pFVar2 = fopen(*(char **)(param_1 + 0x10),"w");

  *(FILE **)(param_1 + 8) = pFVar2;

  if (pFVar2 != (FILE *)0x0) {

    FUN_00402070(param_2);

    return *(int *)(param_1 + 8) != 0;

  }

  FUN_00404cd0();

  return *(int *)(param_1 + 8) != 0;

}





// --- FUN_0040edb0 at 0x0040EDB0 (size: 93) ---


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



undefined4 __thiscall FUN_0040edb0(int *param_1,undefined4 param_2,undefined4 param_3,char *param_4)



{

  if ((char)param_1[3] != '\0') {

    FUN_0040ed10();

    *(undefined1 *)(param_1 + 3) = 0;

  }

  if ((FILE *)param_1[2] != (FILE *)0x0) {

    fprintf((FILE *)param_1[2],"%0.3lf: ",_DAT_008379a8);

    fputs(param_4,(FILE *)param_1[2]);

    (**(code **)(*param_1 + 8))();

    return 1;

  }

  return 0;

}





// --- FUN_0040ee10 at 0x0040EE10 (size: 112) ---


int * __thiscall FUN_0040ee10(int *param_1,int param_2,char param_3,undefined4 param_4)



{

  LONG LVar1;

  undefined *puVar2;

  

  *param_1 = param_2;

  InterlockedIncrement((LONG *)(param_2 + -0x10));

  param_1[1] = 0;

  param_1[2] = 0;

  if (param_3 != '\0') {

    puVar2 = PTR_DAT_008183b4;

    InterlockedIncrement((LONG *)(PTR_DAT_008183b4 + -0x10));

    FUN_0040eb80(param_4,puVar2);

  }

  LVar1 = InterlockedDecrement((LONG *)(param_2 + -0x10));

  if ((LVar1 == 0) && ((undefined4 *)(param_2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(param_2 + -0x14))(1);

  }

  return param_1;

}





// --- FUN_0040ee80 at 0x0040EE80 (size: 91) ---


undefined1 __thiscall FUN_0040ee80(int *param_1,uint param_2,char param_3)



{

  char cVar1;

  uint uVar2;

  

  if ((param_1[1] & 0x7fffffffU) < param_2) {

    uVar2 = param_2;

    if (param_3 == '\0') {

      uVar2 = FUN_00453850(param_2);

    }

    cVar1 = FUN_004180a0(uVar2);

    if (cVar1 == '\0') {

      return 0;

    }

  }

  else {

    uVar2 = param_2;

    if (param_2 < (uint)param_1[2]) {

      do {

        *(undefined4 *)(*param_1 + uVar2 * 4) = 0;

        uVar2 = uVar2 + 1;

      } while (uVar2 < (uint)param_1[2]);

    }

  }

  param_1[2] = param_2;

  return 1;

}





// --- FUN_0040eee0 at 0x0040EEE0 (size: 144) ---


void __fastcall FUN_0040eee0(undefined4 *param_1)



{

  int *piVar1;

  LONG LVar2;

  undefined4 *puVar3;

  

  *param_1 = &PTR_FUN_007955c0;

  if ((FILE *)param_1[2] != (FILE *)0x0) {

    fclose((FILE *)param_1[2]);

  }

  piVar1 = (int *)param_1[5];

  if (piVar1 != (int *)0x0) {

    if ((HANDLE)piVar1[1] != (HANDLE)0x0) {

      CloseHandle((HANDLE)piVar1[1]);

      piVar1[1] = 0;

      piVar1[2] = 0;

    }

    puVar3 = (undefined4 *)(*piVar1 + -0x14);

    LVar2 = InterlockedDecrement((LONG *)(*piVar1 + -0x10));

    if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

      (**(code **)*puVar3)(1);

    }

    operator_delete(piVar1);

  }

  puVar3 = (undefined4 *)(param_1[4] + -0x14);

  param_1[5] = 0;

  LVar2 = InterlockedDecrement((LONG *)(param_1[4] + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  *param_1 = &PTR_FUN_007952f4;

  return;

}





// --- FUN_0040ef70 at 0x0040EF70 (size: 66) ---


undefined4 __thiscall FUN_0040ef70(int *param_1,undefined4 param_2,undefined4 param_3,char *param_4)



{

  if ((char)param_1[3] != '\0') {

    FUN_0040ed10(param_1 + 4);

    *(undefined1 *)(param_1 + 3) = 0;

  }

  if ((FILE *)param_1[2] != (FILE *)0x0) {

    fputs(param_4,(FILE *)param_1[2]);

    (**(code **)(*param_1 + 8))();

    return 1;

  }

  return 0;

}





// --- FUN_0040f020 at 0x0040F020 (size: 72) ---


undefined4 * __thiscall FUN_0040f020(undefined4 *param_1,undefined4 param_2)



{

  param_1[1] = 1;

  *(undefined1 *)(param_1 + 3) = 1;

  *param_1 = &PTR_FUN_007955c0;

  param_1[2] = 0;

  FUN_00401340(param_2);

  param_1[5] = 0;

  DeleteFileA((LPCSTR)param_1[4]);

  *param_1 = &PTR_FUN_007955ec;

  return param_1;

}





// --- FUN_0040f070 at 0x0040F070 (size: 103) ---


void __thiscall FUN_0040f070(int param_1,int param_2,uint param_3,undefined4 param_4)



{

  int iVar1;

  uint *puVar2;

  

  if (*(char *)(param_2 + 0x98 + param_1) == '\0') {

    if ((*(uint *)(param_1 + 0x68) != 0) &&

       (puVar2 = *(uint **)(*(int *)(param_1 + 0x60) + (param_3 % *(uint *)(param_1 + 0x68)) * 4),

       puVar2 != (uint *)0x0)) {

      do {

        if (*puVar2 == param_3) break;

        puVar2 = (uint *)puVar2[1];

      } while (puVar2 != (uint *)0x0);

      if (puVar2 != (uint *)0x0) {

        if ((char)puVar2[2] == '\0') {

          return;

        }

        iVar1 = FUN_0040e910(param_2,param_3,param_4);

        if (iVar1 != 2) {

          return;

        }

      }

    }

    FUN_0040e910(param_2,param_3,param_4);

  }

  return;

}





// --- FUN_0040f0e0 at 0x0040F0E0 (size: 35) ---


void FUN_0040f0e0(undefined4 param_1,undefined4 param_2,undefined4 param_3)



{

  if (DAT_008378d9 != '\0') {

    FUN_0040f070(param_1,param_2,param_3);

  }

  return;

}





// --- FUN_0040f110 at 0x0040F110 (size: 106) ---


void FUN_0040f110(undefined4 param_1)



{

  undefined *puVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined *local_4;

  

  local_4 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  FUN_00402710(&local_4,&DAT_0079559c,param_1);

  puVar1 = local_4;

  if (*(int *)(local_4 + -4) != 1) {

    FUN_00404ef0(local_4,*(int *)(local_4 + -4) + -1);

  }

  puVar3 = (undefined4 *)(puVar1 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return;

}





// --- FUN_0040f180 at 0x0040F180 (size: 430) ---


undefined4 * __thiscall FUN_0040f180(undefined4 *param_1,int param_2)



{

  int iVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined *puVar4;

  undefined4 uVar5;

  undefined4 uVar6;

  undefined4 *local_4;

  

  param_1[1] = 1;

  *param_1 = &PTR_FUN_007955c0;

  param_1[2] = 0;

  *(undefined1 *)(param_1 + 3) = 1;

  puVar4 = PTR_DAT_00818344;

  param_1[4] = PTR_DAT_00818344;

  local_4 = param_1;

  InterlockedIncrement((LONG *)(puVar4 + -0x10));

  FUN_0040c230(&local_4);

  if ((char)param_2 != '\0') {

    thunk_FUN_0040c720(&local_4);

  }

  FUN_0040cda0(&local_4);

  iVar1 = FUN_005df0f5(0xc);

  if (iVar1 == 0) {

    uVar5 = 0;

  }

  else {

    uVar6 = 0;

    uVar5 = 0;

    puVar4 = PTR_DAT_008183b4;

    InterlockedIncrement((LONG *)(PTR_DAT_008183b4 + -0x10));

    uVar5 = FUN_0040ee10(puVar4,uVar5,uVar6);

  }

  param_1[5] = uVar5;

  puVar4 = PTR_DAT_008183b4;

  InterlockedIncrement((LONG *)(PTR_DAT_008183b4 + -0x10));

  iVar1 = FUN_0040eb80(0,puVar4);

  if (iVar1 != 1) {

    FUN_00401340(&DAT_00795500);

    if (*(int *)(param_2 + -4) != 1) {

      FUN_00404ef0(param_2,*(int *)(param_2 + -4) + -1);

    }

    LVar2 = InterlockedDecrement((LONG *)(param_2 + -0x10));

    if ((LVar2 == 0) && ((undefined4 *)(param_2 + -0x14) != (undefined4 *)0x0)) {

      (*(code *)**(undefined4 **)(param_2 + -0x14))(1);

    }

    FUN_0040f110(iVar1);

  }

  FUN_00401340(&DAT_00795600);

  if (*(int *)(param_2 + -4) != 1) {

    FUN_00404ef0(param_2,*(int *)(param_2 + -4) + -1);

  }

  LVar2 = InterlockedDecrement((LONG *)(param_2 + -0x10));

  if ((LVar2 == 0) && ((undefined4 *)(param_2 + -0x14) != (undefined4 *)0x0)) {

    (*(code *)**(undefined4 **)(param_2 + -0x14))(1);

  }

  puVar3 = (undefined4 *)param_1[4];

  if (puVar3 != local_4) {

    LVar2 = InterlockedDecrement(puVar3 + -4);

    if ((LVar2 == 0) && (puVar3 + -5 != (undefined4 *)0x0)) {

      (**(code **)puVar3[-5])(1);

    }

    param_1[4] = local_4;

    InterlockedIncrement(local_4 + -4);

  }

  DeleteFileA((LPCSTR)param_1[4]);

  puVar3 = local_4 + -5;

  LVar2 = InterlockedDecrement(local_4 + -4);

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return param_1;

}





// --- FUN_0040f330 at 0x0040F330 (size: 30) ---


void * __thiscall FUN_0040f330(void *param_1,byte param_2)



{

  FUN_0040eee0();

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040f350 at 0x0040F350 (size: 84) ---


undefined4 __thiscall FUN_0040f350(int param_1,undefined4 param_2)



{

  undefined4 *puVar1;

  

  if (*(int *)(param_1 + 0xa0) == 0) {

    puVar1 = (undefined4 *)FUN_005df0f5(0x18);

    if (puVar1 == (undefined4 *)0x0) {

      puVar1 = (undefined4 *)0x0;

    }

    else {

      FUN_0040f180(param_2);

      *puVar1 = &PTR_FUN_007955ec;

    }

    *(undefined4 **)(param_1 + 0xa0) = puVar1;

  }

  InterlockedIncrement((LONG *)(*(int *)(param_1 + 0xa0) + 4));

  return *(undefined4 *)(param_1 + 0xa0);

}





// --- FUN_0040f3b0 at 0x0040F3B0 (size: 105) ---


undefined4 __fastcall FUN_0040f3b0(int param_1)



{

  undefined4 *puVar1;

  int iVar2;

  LONG LVar3;

  uint uVar4;

  

  while (*(int *)(param_1 + 0x14) != 0) {

    iVar2 = *(int *)(param_1 + 0x14) + -1;

    *(int *)(param_1 + 0x14) = iVar2;

    puVar1 = *(undefined4 **)(*(int *)(param_1 + 0xc) + iVar2 * 4);

    *(undefined4 *)(*(int *)(param_1 + 0xc) + iVar2 * 4) = 0;

    LVar3 = InterlockedDecrement(puVar1 + 1);

    if ((LVar3 == 0) && (puVar1 != (undefined4 *)0x0)) {

      (**(code **)*puVar1)(1);

    }

  }

  uVar4 = 0;

  if (*(int *)(param_1 + 0x20) != 0) {

    do {

      *(undefined4 *)(*(int *)(param_1 + 0x18) + uVar4 * 4) = 0;

      uVar4 = uVar4 + 1;

    } while (uVar4 < *(uint *)(param_1 + 0x20));

  }

  *(undefined4 *)(param_1 + 0x20) = 0;

  return CONCAT31((int3)(uVar4 >> 8),1);

}





// --- FUN_0040f420 at 0x0040F420 (size: 118) ---


/* WARNING: Function: __chkstk replaced with injection: alloca_probe */

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



void FUN_0040f420(undefined4 param_1,undefined4 param_2,undefined4 param_3,undefined4 param_4)



{

  undefined1 local_1000 [4092];

  undefined4 uStack_4;

  

  uStack_4 = 0x40f42a;

  if (DAT_008378d9 != '\0') {

    FUN_004062a0(param_3,param_4);

    if (DAT_008378d9 != '\0') {

      FUN_0040f070(param_1,param_2,local_1000);

    }

  }

  return;

}





// --- FUN_0040f4a0 at 0x0040F4A0 (size: 30) ---


void FUN_0040f4a0(undefined4 *param_1,undefined4 param_2)



{

  FUN_0040f420(*param_1,param_1[1],param_2,&stack0x0000000c);

  return;

}





// --- FUN_0040f4c0 at 0x0040F4C0 (size: 25) ---


undefined4 FUN_0040f4c0(void)



{

  undefined4 uVar1;

  

  if (DAT_008378d9 == '\0') {

    return 0;

  }

  uVar1 = FUN_0040f350(0);

  return uVar1;

}





// --- FUN_0040f4e0 at 0x0040F4E0 (size: 109) ---


uint __thiscall FUN_0040f4e0(int *param_1,int *param_2)



{

  int iVar1;

  uint uVar2;

  undefined4 uVar3;

  int *piVar4;

  

  uVar2 = 0;

  if (param_1[2] != 0) {

    piVar4 = (int *)*param_1;

    do {

      if (*piVar4 == *param_2) {

        if (uVar2 != 0xffffffff) goto LAB_0040f52f;

        break;

      }

      uVar2 = uVar2 + 1;

      piVar4 = piVar4 + 1;

    } while (uVar2 < (uint)param_1[2]);

  }

  if ((param_1[1] & 0x7fffffffU) <= (uint)param_1[2]) {

    uVar3 = FUN_004077f0((param_1[1] & 0x7fffffffU) + 1);

    uVar2 = FUN_00408220(uVar3);

    if ((char)uVar2 == '\0') {

LAB_0040f52f:

      return uVar2 & 0xffffff00;

    }

  }

  iVar1 = param_1[2];

  *(int *)(*param_1 + iVar1 * 4) = *param_2;

  param_1[2] = param_1[2] + 1;

  return CONCAT31((int3)((uint)iVar1 >> 8),1);

}





// --- FUN_0040f550 at 0x0040F550 (size: 151) ---


undefined4 * __thiscall FUN_0040f550(undefined4 *param_1,uint param_2)



{

  undefined *puVar1;

  uint *puVar2;

  undefined4 uVar3;

  uint uVar4;

  int iVar5;

  undefined4 *puVar6;

  uint local_4;

  

  local_4 = param_2;

  param_2 = param_2 & 0xffffff00;

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  *param_1 = &PTR_FUN_007955bc;

  puVar1 = PTR_DAT_00818558;

  puVar2 = (uint *)FUN_004064a0(PTR_DAT_00818554,PTR_DAT_00818558,&local_4,param_2,0);

  if (puVar2 == (uint *)puVar1) {

    puVar2 = puVar2 + -1;

  }

  uVar4 = *puVar2;

  param_1[0x1a] = uVar4;

  if (uVar4 < 0x18) {

    param_1[0x18] = param_1 + 1;

  }

  else {

    uVar3 = thunk_FUN_005df0f5(uVar4 * 4);

    param_1[0x18] = uVar3;

  }

  param_1[0x19] = (undefined4 *)param_1[0x18] + param_1[0x1a];

  puVar6 = (undefined4 *)param_1[0x18];

  for (uVar4 = param_1[0x1a] & 0x3fffffff; uVar4 != 0; uVar4 = uVar4 - 1) {

    *puVar6 = 0;

    puVar6 = puVar6 + 1;

  }

  for (iVar5 = 0; iVar5 != 0; iVar5 = iVar5 + -1) {

    *(undefined1 *)puVar6 = 0;

    puVar6 = (undefined4 *)((int)puVar6 + 1);

  }

  return param_1;

}





// --- FUN_0040f5f0 at 0x0040F5F0 (size: 101) ---


undefined4 __thiscall FUN_0040f5f0(int param_1,int param_2,undefined4 param_3)



{

  char cVar1;

  uint uVar2;

  undefined4 uVar3;

  

  cVar1 = FUN_0040f4e0(&param_2);

  if (cVar1 == '\0') {

    return 0;

  }

  InterlockedIncrement((LONG *)(param_2 + 4));

  uVar2 = *(uint *)(param_1 + 0x1c) & 0x7fffffff;

  if (uVar2 <= *(uint *)(param_1 + 0x20)) {

    uVar3 = FUN_00453850(uVar2 + 1);

    cVar1 = FUN_004180a0(uVar3);

    if (cVar1 == '\0') {

      return 1;

    }

  }

  *(undefined4 *)(*(int *)(param_1 + 0x18) + *(int *)(param_1 + 0x20) * 4) = param_3;

  *(int *)(param_1 + 0x20) = *(int *)(param_1 + 0x20) + 1;

  return 1;

}





// --- FUN_0040f660 at 0x0040F660 (size: 79) ---


uint __thiscall FUN_0040f660(int param_1,uint *param_2)



{

  uint *puVar1;

  uint *puVar2;

  

  puVar1 = (uint *)(*(int *)(param_1 + 0x60) + (*param_2 % *(uint *)(param_1 + 0x68)) * 4);

  puVar2 = (uint *)*puVar1;

  do {

    if (puVar2 == (uint *)0x0) {

LAB_0040f68b:

      param_2[1] = *puVar1;

      *puVar1 = (uint)param_2;

      if (puVar1 < *(uint **)(param_1 + 100)) {

        *(uint **)(param_1 + 100) = puVar1;

      }

      *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + 1;

      return 1;

    }

    if (*puVar2 == *param_2) {

      if (puVar2 != (uint *)0x0) {

        return (uint)puVar2 & 0xffffff00;

      }

      goto LAB_0040f68b;

    }

    puVar2 = (uint *)puVar2[1];

  } while( true );

}





// --- FUN_0040f6c0 at 0x0040F6C0 (size: 188) ---


void __fastcall FUN_0040f6c0(int param_1)



{

  int iVar1;

  void *pvVar2;

  void *pvVar3;

  int *piVar4;

  void *pvVar5;

  

  iVar1 = *(int *)(param_1 + 0x6c);

  do {

    if (iVar1 == 0) {

      return;

    }

    piVar4 = *(int **)(param_1 + 100);

    while (piVar4 != (int *)(*(int *)(param_1 + 0x60) + *(int *)(param_1 + 0x68) * 4)) {

      if (**(int **)(param_1 + 100) != 0) {

        piVar4 = *(int **)(param_1 + 100);

        pvVar5 = (void *)*piVar4;

        goto LAB_0040f6ff;

      }

      piVar4 = *(int **)(param_1 + 100) + 1;

      *(int **)(param_1 + 100) = piVar4;

    }

    piVar4 = (int *)0x0;

    pvVar5 = (void *)0x0;

LAB_0040f6ff:

    pvVar3 = (void *)*piVar4;

    if (pvVar3 == pvVar5) {

LAB_0040f712:

      *piVar4 = *(int *)((int)pvVar3 + 4);

    }

    else {

      do {

        pvVar2 = pvVar3;

        pvVar3 = *(void **)((int)pvVar2 + 4);

      } while (pvVar3 != pvVar5);

      if (pvVar2 == (void *)0x0) goto LAB_0040f712;

      *(undefined4 *)((int)pvVar2 + 4) = *(undefined4 *)((int)pvVar3 + 4);

    }

    *(int *)(param_1 + 0x6c) = *(int *)(param_1 + 0x6c) + -1;

    if (pvVar5 != (void *)0x0) {

      FUN_0040f3b0();

      if ((*(uint *)((int)pvVar5 + 0x1c) & 0x80000000) == 0x80000000) {

        operator_delete__(*(void **)((int)pvVar5 + 0x18));

      }

      if ((*(uint *)((int)pvVar5 + 0x10) & 0x80000000) == 0x80000000) {

        operator_delete__(*(void **)((int)pvVar5 + 0xc));

      }

      operator_delete(pvVar5);

    }

    iVar1 = *(int *)(param_1 + 0x6c);

  } while( true );

}





// --- FUN_0040f780 at 0x0040F780 (size: 98) ---


int __fastcall FUN_0040f780(int param_1)



{

  FUN_0040f550(10);

  *(undefined4 *)(param_1 + 0x70) = 10;

  *(undefined4 *)(param_1 + 0x74) = 0;

  *(undefined4 *)(param_1 + 0x78) = 0;

  *(undefined1 *)(param_1 + 0x7c) = 1;

  *(undefined4 *)(param_1 + 0x80) = 0;

  *(undefined4 *)(param_1 + 0x84) = 0;

  *(undefined4 *)(param_1 + 0x88) = 0;

  *(undefined4 *)(param_1 + 0x8c) = 0;

  *(undefined4 *)(param_1 + 0x90) = 0;

  *(undefined4 *)(param_1 + 0x94) = 0;

  *(undefined4 *)(param_1 + 0xa0) = 0;

  *(undefined4 *)(param_1 + 0xa4) = 0;

  *(undefined4 *)(param_1 + 0xa8) = 0;

  *(undefined4 *)(param_1 + 0x98) = 0;

  *(undefined2 *)(param_1 + 0x9c) = 0;

  FUN_0040f660((undefined4 *)(param_1 + 0x74));

  DAT_008378d8 = 1;

  return param_1;

}





// --- FUN_0040f7f0 at 0x0040F7F0 (size: 265) ---


void __fastcall FUN_0040f7f0(undefined4 *param_1)



{

  undefined4 *puVar1;

  LONG LVar2;

  

  DAT_008378d8 = 0;

  DAT_008378d9 = 0;

  FUN_00410e70(&DAT_00795598);

  FUN_0040f6c0();

  puVar1 = (undefined4 *)param_1[0x28];

  if (puVar1 != (undefined4 *)0x0) {

    LVar2 = InterlockedDecrement(puVar1 + 1);

    if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

      (**(code **)*puVar1)(1);

    }

    param_1[0x28] = 0;

  }

  puVar1 = (undefined4 *)param_1[0x29];

  if (puVar1 != (undefined4 *)0x0) {

    LVar2 = InterlockedDecrement(puVar1 + 1);

    if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

      (**(code **)*puVar1)(1);

    }

    param_1[0x29] = 0;

  }

  puVar1 = (undefined4 *)param_1[0x2a];

  if (puVar1 != (undefined4 *)0x0) {

    LVar2 = InterlockedDecrement(puVar1 + 1);

    if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

      (**(code **)*puVar1)(1);

    }

    param_1[0x2a] = 0;

  }

  FUN_0040f3b0();

  if ((param_1[0x24] & 0x80000000) == 0x80000000) {

    operator_delete__((void *)param_1[0x23]);

  }

  if ((param_1[0x21] & 0x80000000) == 0x80000000) {

    operator_delete__((void *)param_1[0x20]);

  }

  *param_1 = &PTR_FUN_007955bc;

  if ((undefined4 *)param_1[0x18] != param_1 + 1) {

    operator_delete__((undefined4 *)param_1[0x18]);

  }

  param_1[0x18] = 0;

  param_1[0x19] = 0;

  param_1[0x1a] = 0;

  param_1[0x1b] = 0;

  return;

}





// --- FUN_0040f900 at 0x0040F900 (size: 134) ---


undefined4 __thiscall FUN_0040f900(int param_1,uint param_2,undefined4 param_3)



{

  uint *puVar1;

  

  for (puVar1 = *(uint **)(*(int *)(param_1 + 0x60) + (param_2 % *(uint *)(param_1 + 0x68)) * 4);

      (puVar1 != (uint *)0x0 && (*puVar1 != param_2)); puVar1 = (uint *)puVar1[1]) {

  }

  if (puVar1 == (uint *)0x0) {

    puVar1 = (uint *)FUN_005df0f5(0x24);

    if (puVar1 == (uint *)0x0) {

      puVar1 = (uint *)0x0;

    }

    else {

      *puVar1 = param_2;

      puVar1[1] = 0;

      *(undefined1 *)(puVar1 + 2) = 1;

      puVar1[3] = 0;

      puVar1[4] = 0;

      puVar1[5] = 0;

      puVar1[6] = 0;

      puVar1[7] = 0;

      puVar1[8] = 0;

    }

    FUN_0040f660(puVar1);

  }

  *(int *)(param_1 + 0x70) = *(int *)(param_1 + 0x70) + 1;

  FUN_0040f5f0(param_3,*(undefined4 *)(param_1 + 0x70));

  return *(undefined4 *)(param_1 + 0x70);

}





// --- FUN_0040f990 at 0x0040F990 (size: 166) ---


void __thiscall FUN_0040f990(int param_1,undefined4 param_2)



{

  undefined4 *puVar1;

  LONG LVar2;

  

  puVar1 = (undefined4 *)FUN_0040f350(param_2);

  FUN_0040f5f0(puVar1,0);

  LVar2 = InterlockedDecrement(puVar1 + 1);

  if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

    (**(code **)*puVar1)(1);

  }

  if (*(int *)(param_1 + 0xa8) == 0) {

    puVar1 = (undefined4 *)FUN_005df0f5(8);

    if (puVar1 == (undefined4 *)0x0) {

      puVar1 = (undefined4 *)0x0;

    }

    else {

      puVar1[1] = 1;

      *puVar1 = &PTR_FUN_007955b0;

    }

    *(undefined4 **)(param_1 + 0xa8) = puVar1;

  }

  InterlockedIncrement((LONG *)(*(int *)(param_1 + 0xa8) + 4));

  puVar1 = *(undefined4 **)(param_1 + 0xa8);

  FUN_0040f5f0(puVar1,1);

  LVar2 = InterlockedDecrement(puVar1 + 1);

  if ((LVar2 == 0) && (puVar1 != (undefined4 *)0x0)) {

    (**(code **)*puVar1)(1);

  }

  return;

}





// --- FUN_0040fa40 at 0x0040FA40 (size: 32) ---


void FUN_0040fa40(undefined4 param_1)



{

  if (DAT_008378d9 == '\0') {

    FUN_0040f990(param_1);

    DAT_008378d9 = '\x01';

  }

  return;

}





// --- FUN_0040fa60 at 0x0040FA60 (size: 33) ---


undefined4 FUN_0040fa60(undefined4 param_1,undefined4 param_2)



{

  undefined4 uVar1;

  

  if (DAT_008378d9 == '\0') {

    return 0;

  }

  uVar1 = FUN_0040f900(param_1,param_2);

  return uVar1;

}





// --- FUN_0040fa90 at 0x0040FA90 (size: 12) ---


time_t FUN_0040fa90(void)



{

  time_t tVar1;

  

  tVar1 = time((time_t *)0x0);

  return tVar1;

}





// --- FUN_0040faa0 at 0x0040FAA0 (size: 39) ---


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



float10 FUN_0040faa0(void)



{

  int iVar1;

  float10 fVar2;

  

  iVar1 = DAT_008379a0;

  if (DAT_008379b8 == '\0') {

    return (float10)_DAT_00795610;

  }

  fVar2 = (float10)FUN_00411280(0);

  return fVar2 + (float10)*(double *)(iVar1 + 0x58);

}





// --- FUN_0040fad0 at 0x0040FAD0 (size: 33) ---


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



float10 FUN_0040fad0(void)



{

  float10 fVar1;

  

  if (DAT_008379b8 == '\0') {

    return (float10)_DAT_00795610;

  }

  fVar1 = (float10)FUN_00411280(0);

  return fVar1;

}





// --- FUN_0040fb00 at 0x0040FB00 (size: 194) ---


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



void FUN_0040fb00(double *param_1)



{

  double *pdVar1;

  double *pdVar2;

  double dVar3;

  double dVar4;

  int iVar5;

  float10 fVar6;

  

  iVar5 = DAT_008379a0;

  if (DAT_008379b8 != '\0') {

    dVar3 = *param_1;

    pdVar1 = (double *)(DAT_008379a0 + 0x68);

    if (*(double *)(DAT_008379a0 + 0x68) < dVar3) {

      dVar4 = *(double *)(DAT_008379a0 + 0x60);

      pdVar2 = (double *)(DAT_008379a0 + 0x60);

      fVar6 = (float10)FUN_00411280(1);

      *pdVar2 = (double)fVar6;

      if (fVar6 <= (float10)dVar4) {

        *pdVar2 = dVar4;

      }

      else {

        *pdVar1 = (double)(fVar6 + (float10)*(double *)(iVar5 + 0x58));

      }

      if (*pdVar1 + _DAT_00795608 < dVar3) {

        *(double *)(iVar5 + 0x58) = dVar3 - *pdVar2;

        *pdVar1 = dVar3;

      }

      else if (_DAT_00795608 + dVar3 < *pdVar1) {

        *pdVar2 = *pdVar2 - (*pdVar1 - dVar3);

        *pdVar1 = dVar3;

      }

    }

    _DAT_008379b0 = *(undefined8 *)(DAT_008379a0 + 0x60);

    _DAT_008379a8 = *(undefined8 *)(DAT_008379a0 + 0x68);

  }

  return;

}





// --- FUN_0040fbd0 at 0x0040FBD0 (size: 99) ---


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



void FUN_0040fbd0(void)



{

  double *pdVar1;

  double dVar2;

  int iVar3;

  float10 fVar4;

  

  iVar3 = DAT_008379a0;

  if (DAT_008379b8 != '\0') {

    dVar2 = *(double *)(DAT_008379a0 + 0x60);

    pdVar1 = (double *)(DAT_008379a0 + 0x60);

    fVar4 = (float10)FUN_00411280(1);

    *pdVar1 = (double)fVar4;

    if (fVar4 <= (float10)dVar2) {

      *pdVar1 = dVar2;

    }

    else {

      *(double *)(iVar3 + 0x68) = (double)(fVar4 + (float10)*(double *)(iVar3 + 0x58));

    }

    _DAT_008379b0 = *(undefined8 *)(DAT_008379a0 + 0x60);

    _DAT_008379a8 = *(undefined8 *)(DAT_008379a0 + 0x68);

  }

  return;

}





// --- FUN_0040fc40 at 0x0040FC40 (size: 61) ---


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



undefined4 * __fastcall FUN_0040fc40(undefined4 *param_1)



{

  param_1[1] = 1;

  *param_1 = &PTR_FUN_007952f4;

  FUN_00411190();

  *(undefined8 *)(param_1 + 0x16) = _DAT_00795610;

  *param_1 = &PTR_FUN_007952f4;

  *(undefined8 *)(param_1 + 0x18) = _DAT_00795610;

  *(undefined8 *)(param_1 + 0x1a) = _DAT_00795610;

  return param_1;

}





// --- FUN_0040fc80 at 0x0040FC80 (size: 31) ---


undefined4 * __thiscall FUN_0040fc80(undefined4 *param_1,byte param_2)



{

  *param_1 = &PTR_FUN_007952f4;

  if ((param_2 & 1) != 0) {

    operator_delete(param_1);

  }

  return param_1;

}





// --- FUN_0040fca0 at 0x0040FCA0 (size: 44) ---


void FUN_0040fca0(void)



{

  int iVar1;

  

  if (DAT_008379a0 == 0) {

    iVar1 = FUN_005df0f5(0x78);

    if (iVar1 != 0) {

      DAT_008379a0 = FUN_0040fc40();

      return;

    }

    DAT_008379a0 = 0;

  }

  return;

}





// --- FUN_0040fcd0 at 0x0040FCD0 (size: 95) ---


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



void FUN_0040fcd0(void)



{

  int iVar1;

  

  if (DAT_008379b8 == '\0') {

    _DAT_008379a8 = _DAT_00795610;

    _DAT_008379b0 = _DAT_00795610;

    if (DAT_008379a0 == 0) {

      iVar1 = FUN_005df0f5(0x78);

      if (iVar1 == 0) {

        DAT_008379a0 = 0;

      }

      else {

        DAT_008379a0 = FUN_0040fc40();

      }

    }

    iVar1 = DAT_008379a0;

    FUN_004111b0();

    *(undefined1 *)(iVar1 + 0x70) = 1;

    DAT_008379b8 = '\x01';

  }

  return;

}





// --- FUN_0040fd30 at 0x0040FD30 (size: 170) ---


uint __thiscall FUN_0040fd30(undefined4 *param_1,char *param_2)



{

  uint *puVar1;

  undefined2 *puVar2;

  undefined4 *puVar3;

  undefined4 *puVar4;

  uint uVar5;

  int iVar6;

  

  puVar1 = param_1 + 3;

  puVar2 = (undefined2 *)((int)param_1 + 10);

  puVar3 = param_1 + 2;

  puVar4 = param_1 + 1;

  iVar6 = sscanf(param_2,"%08lX-%04hX-%04hX-%04hX-%04hX%08lX",param_1,puVar4,(int)param_1 + 6,puVar3

                 ,puVar2,puVar1);

  if (iVar6 != 6) {

    *puVar3 = 0;

    *param_1 = 0;

    *puVar4 = 0;

    *puVar1 = 0;

    return (uint)puVar4 & 0xffffff00;

  }

  *(ushort *)puVar3 =

       CONCAT11((char)*(undefined2 *)puVar3,(char)((ushort)*(undefined2 *)puVar3 >> 8));

  *puVar2 = CONCAT11((char)*puVar2,(char)((ushort)*puVar2 >> 8));

  uVar5 = *puVar1;

  *puVar1 = (uVar5 & 0xff0000 | uVar5 >> 0x10) >> 8 | (uVar5 & 0xff00 | uVar5 << 0x10) << 8;

  return CONCAT31((int3)((uVar5 << 0x10) >> 8),1);

}





// --- FUN_0040fde0 at 0x0040FDE0 (size: 152) ---


undefined4 * __thiscall FUN_0040fde0(undefined4 *param_1,undefined4 *param_2)



{

  undefined *puVar1;

  LONG LVar2;

  undefined4 *puVar3;

  undefined *local_4;

  

  local_4 = PTR_DAT_00818344;

  InterlockedIncrement((LONG *)(PTR_DAT_00818344 + -0x10));

  FUN_00402710(&local_4,"%08X-%04hX-%04hX-%02X%02X-%02X%02X%02X%02X%02X%02X",*param_1,

               *(undefined2 *)(param_1 + 1),*(undefined2 *)((int)param_1 + 6),

               *(undefined1 *)(param_1 + 2),*(undefined1 *)((int)param_1 + 9),

               *(undefined1 *)((int)param_1 + 10),*(undefined1 *)((int)param_1 + 0xb),

               *(undefined1 *)(param_1 + 3),*(undefined1 *)((int)param_1 + 0xd),

               *(undefined1 *)((int)param_1 + 0xe),*(undefined1 *)((int)param_1 + 0xf));

  puVar1 = local_4;

  *param_2 = local_4;

  InterlockedIncrement((LONG *)(local_4 + -0x10));

  puVar3 = (undefined4 *)(puVar1 + -0x14);

  LVar2 = InterlockedDecrement((LONG *)(puVar1 + -0x10));

  if ((LVar2 == 0) && (puVar3 != (undefined4 *)0x0)) {

    (**(code **)*puVar3)(1);

  }

  return param_2;

}





// --- FUN_0040fe80 at 0x0040FE80 (size: 108) ---


void __fastcall FUN_0040fe80(undefined1 *param_1)



{

  HANDLE hConsoleOutput;

  BOOL BVar1;

  DWORD DVar2;

  _CONSOLE_SCREEN_BUFFER_INFO local_18;

  

  *(undefined4 *)(param_1 + 4) = 0;

  *(undefined2 *)(param_1 + 8) = 8;

  *param_1 = 1;

  hConsoleOutput = GetStdHandle(0xfffffff5);

  BVar1 = GetConsoleScreenBufferInfo(hConsoleOutput,&local_18);

  if (BVar1 == 0) {

    DVar2 = GetLastError();

    fprintf((FILE *)(_iob_exref + 0x40),"GetConsoleScreenBufferInfo %d",DVar2);

    return;

  }

  *(HANDLE *)(param_1 + 4) = hConsoleOutput;

  *(WORD *)(param_1 + 8) = local_18.wAttributes;

  *(WORD *)(param_1 + 10) = local_18.wAttributes;

  return;

}





// --- FUN_0040fef0 at 0x0040FEF0 (size: 46) ---


void __thiscall FUN_0040fef0(char *param_1,byte param_2)



{

  if (*param_1 == '\0') {

    FUN_0040fe80();

  }

  *(ushort *)(param_1 + 10) = *(ushort *)(param_1 + 10) ^ (byte)(param_1[10] ^ param_2) & 0xf;

  SetConsoleTextAttribute(*(HANDLE *)(param_1 + 4),*(WORD *)(param_1 + 10));

  return;

}





// --- FUN_0040ff20 at 0x0040FF20 (size: 48) ---


void __thiscall FUN_0040ff20(char *param_1,byte param_2)



{

  if (*param_1 == '\0') {

    FUN_0040fe80();

  }

  *(ushort *)(param_1 + 10) = *(ushort *)(param_1 + 10) ^ (byte)(param_1[10] ^ param_2) & 0xf0;

  SetConsoleTextAttribute(*(HANDLE *)(param_1 + 4),*(WORD *)(param_1 + 10));

  return;

}





// --- FUN_0040ff50 at 0x0040FF50 (size: 34) ---


void __fastcall FUN_0040ff50(char *param_1)



{

  if (*param_1 == '\0') {

    FUN_0040fe80();

  }

  *(WORD *)(param_1 + 10) = *(WORD *)(param_1 + 8);

  SetConsoleTextAttribute(*(HANDLE *)(param_1 + 4),*(WORD *)(param_1 + 8));

  return;

}





// --- FUN_0040ff80 at 0x0040FF80 (size: 552) ---


char * FUN_0040ff80(char *param_1)



{

  int iVar1;

  bool bVar2;

  bool bVar3;

  int iVar4;

  uint uVar5;

  undefined2 extraout_var;

  undefined2 extraout_var_00;

  undefined2 uVar6;

  char *_Src;

  int *piVar7;

  uint uVar8;

  int local_34;

  uint local_30;

  char *local_2c;

  int local_28 [10];

  

  if ((*param_1 != '\x1b') || (local_2c = param_1, param_1[1] != '[')) {

    return (char *)0x0;

  }

  _Src = param_1 + 2;

  param_1 = (char *)0x0;

  bVar2 = true;

  piVar7 = local_28;

  do {

    iVar4 = sscanf(_Src,"%d%n",piVar7,&local_34);

    if (iVar4 == 0) break;

    _Src = _Src + local_34;

    if (*_Src == ';') {

      _Src = _Src + 1;

    }

    else {

      bVar2 = false;

    }

    param_1 = (char *)((int)param_1 + 1);

    piVar7 = piVar7 + 1;

  } while (bVar2);

  if (*_Src != 'm') {

    return (char *)0x0;

  }

  if (param_1 == (char *)0x1) {

    switch(local_28[0]) {

    case 0:

      FUN_0040ff50();

      return _Src + (1 - (int)local_2c);

    case 1:

    case 4:

      uVar6 = extraout_var;

      if (DAT_008379cc == '\0') {

        FUN_0040fe80();

        uVar6 = extraout_var_00;

      }

      FUN_0040fef0(CONCAT31((int3)(CONCAT22(uVar6,DAT_008379d6) >> 8),(char)DAT_008379d6) | 8);

      return _Src + (1 - (int)local_2c);

    case 0x16:

    case 0x18:

      if (DAT_008379cc == '\0') {

        FUN_0040fe80();

      }

      FUN_0040fef0(DAT_008379d6 & 0xfff7);

      return _Src + (1 - (int)local_2c);

    }

  }

  if (DAT_008379cc == '\0') {

    FUN_0040fe80();

  }

  local_30 = CONCAT22(local_30._2_2_,DAT_008379d6);

  bVar2 = false;

  bVar3 = false;

  if (0 < (int)param_1) {

    iVar4 = 0;

    uVar8 = local_30;

    do {

      iVar1 = local_28[iVar4];

      switch(iVar1) {

      case 0:

        bVar2 = true;

        break;

      case 1:

        bVar3 = true;

        break;

      case 0x1e:

      case 0x1f:

      case 0x20:

      case 0x21:

      case 0x22:

      case 0x23:

      case 0x24:

      case 0x25:

        uVar5 = iVar1 - 0x1e;

        uVar8 = uVar8 & 0xfff8;

        if ((uVar5 & 1) != 0) {

          uVar8 = uVar8 | 4;

        }

        if ((uVar5 & 2) != 0) {

          uVar8 = uVar8 | 2;

        }

        if ((uVar5 & 4) != 0) {

          uVar8 = uVar8 | 1;

        }

        if (bVar2) {

          uVar8 = uVar8 & 0xfff7;

        }

        if (bVar3) {

          uVar8 = uVar8 | 8;

        }

        FUN_0040fef0(uVar8);

        goto LAB_0041017f;

      case 0x28:

      case 0x29:

      case 0x2a:

      case 0x2b:

      case 0x2c:

      case 0x2d:

      case 0x2e:

      case 0x2f:

        uVar5 = iVar1 - 0x28;

        uVar8 = uVar8 & 0xff8f;

        if ((uVar5 & 1) != 0) {

          uVar8 = uVar8 | 0x40;

        }

        if ((uVar5 & 2) != 0) {

          uVar8 = uVar8 | 0x20;

        }

        if ((uVar5 & 4) != 0) {

          uVar8 = uVar8 | 0x10;

        }

        if (bVar2) {

          uVar8 = uVar8 & 0xff7f;

        }

        if (bVar3) {

          uVar8 = uVar8 | 0x80;

        }

        FUN_0040ff20(uVar8);

LAB_0041017f:

        bVar2 = false;

        bVar3 = false;

      }

      iVar4 = iVar4 + 1;

    } while (iVar4 < (int)param_1);

  }

  return _Src + (1 - (int)local_2c);

}





