// Recovered decompilation of functions attributed to bt_l4/btl4vid.cpp
// (from BTL4OPT.EXE via embedded assert paths). Pseudocode — reconstruct against the header.

/* ---- @ 004cdac0 ---- */

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

void __cdecl
FUN_004cdac0(int param_1,float param_2,int param_3,undefined4 *param_4,int param_5,
            undefined4 param_6,undefined4 param_7,undefined4 param_8,int param_9,undefined4 param_10
            ,undefined4 param_11,int param_12,undefined4 param_13,undefined4 param_14)

{
  float fVar1;
  float fVar2;
  byte *pbVar3;
  byte *pbVar4;
  
  if (9 < *(int *)(param_1 + 0x38)) {
    FUN_0040385c(s_Tried_to_display_too_many_weapon_0051d24f,
                 s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d272,0x338);
  }
  *(undefined4 *)(param_1 + 100 + *(int *)(param_1 + 0x38) * 4) = param_11;
  *(undefined4 *)(param_1 + 0x8c + *(int *)(param_1 + 0x38) * 4) = param_10;
  *(undefined4 *)(param_1 + 0xb4 + *(int *)(param_1 + 0x38) * 4) = param_13;
  *(int *)(param_1 + 0x130 + *(int *)(param_1 + 0x38) * 4) = param_9;
  *(undefined4 *)(param_1 + 0xdc + *(int *)(param_1 + 0x38) * 4) = *(undefined4 *)(param_9 + 0x14);
  *(int *)(param_1 + 0x158 + *(int *)(param_1 + 0x38) * 4) = param_12;
  *(undefined4 *)(param_1 + 0x104 + *(int *)(param_1 + 0x38) * 4) = *(undefined4 *)(param_12 + 0x14)
  ;
  *(undefined4 **)(param_1 + 0x18c + *(int *)(param_1 + 0x38) * 4) = param_4;
  *(undefined4 *)(param_1 + 0x1b4 + *(int *)(param_1 + 0x38) * 4) = *param_4;
  *(undefined4 *)(param_1 + 0x3c + *(int *)(param_1 + 0x38) * 4) = param_14;
  pbVar3 = (byte *)FUN_00487f34();
  pbVar4 = (byte *)FUN_00487f34();
  *(byte **)(param_1 + 0x2b0 + *(int *)(param_1 + 0x38) * 4) = pbVar3;
  *(byte **)(param_1 + 0x288 + *(int *)(param_1 + 0x38) * 4) = pbVar4;
  if (*(float *)(param_1 + 0x230) <= param_2) {
    if (*(float *)(param_1 + 0x22c) < param_2) {
      param_2 = *(float *)(param_1 + 0x22c);
    }
  }
  else {
    param_2 = *(float *)(param_1 + 0x230);
  }
  fVar2 = *(float *)(param_1 + 0x1fc) + *(float *)(param_1 + 0x208) +
          (float)param_3 * (float)_DAT_004cdce8;
  fVar1 = -*(float *)(param_1 + 0x204) *
          ((param_2 - *(float *)(param_1 + 0x230)) / *(float *)(param_1 + 0x234)) +
          *(float *)(param_1 + 0x200);
  FUN_00487fbc((int)pbVar3,1);
  FUN_00488630((int)pbVar3,param_6,param_7,param_8);
  FUN_0048847c((int)pbVar3,fVar2,fVar1,0x3c449ba6,1);
  FUN_00488630((int)pbVar3,0,0,0);
  FUN_0048847c((int)pbVar3,fVar2,fVar1,0x3c656042,0);
  if (param_5 != 0) {
    FUN_00488630((int)pbVar3,0x3f333333,0x3f333333,0x3f333333);
    FUN_00488340((int)pbVar3);
    FUN_00488408((int)pbVar3,fVar2,fVar1);
    FUN_004883a4((int)pbVar3);
  }
  FUN_00488030((int)pbVar3);
  FUN_00488054(pbVar3);
  FUN_00487fbc((int)pbVar4,1);
  FUN_00488630((int)pbVar4,0,0,0);
  FUN_0048847c((int)pbVar4,fVar2,fVar1,0x3c656042,0);
  FUN_00488030((int)pbVar4);
  FUN_00488054(pbVar4);
  *(int *)(param_1 + 0x38) = *(int *)(param_1 + 0x38) + 1;
  return;
}



/* ---- @ 004cef28 ---- */

undefined4 __cdecl FUN_004cef28(int param_1,int param_2,undefined4 param_3,int param_4)

{
  char *pcVar1;
  char cVar2;
  int iVar3;
  int *piVar4;
  undefined4 *puVar5;
  undefined4 *puVar6;
  char *pcVar7;
  int iVar8;
  int iVar9;
  uint uVar10;
  uint uVar11;
  char *pcVar12;
  bool bVar13;
  undefined4 uVar14;
  undefined4 local_320 [3];
  undefined4 local_314 [3];
  float local_308;
  undefined4 local_304;
  undefined4 local_300;
  float local_2fc [3];
  undefined4 local_2f0 [12];
  int local_2c0 [7];
  int local_2a4 [7];
  undefined4 local_288 [12];
  int local_258 [7];
  char local_23c [40];
  undefined4 *local_214;
  undefined4 *local_210;
  int *local_20c;
  int *local_208;
  int local_204;
  int local_200;
  int local_1fc;
  undefined4 *local_1f8;
  undefined4 *local_1f4;
  int *local_1f0;
  undefined4 local_1ec;
  int local_1e8;
  undefined4 *local_1e4;
  undefined4 *local_1e0;
  undefined4 *local_1dc;
  int local_1d8;
  undefined4 *local_1d4;
  undefined4 *local_1d0;
  undefined4 *local_1cc;
  undefined4 *local_1c8;
  undefined4 *local_1c4;
  undefined4 *local_1c0;
  int local_1bc;
  int *local_1b8;
  undefined4 *local_1b4;
  int local_1b0;
  undefined4 *local_1ac;
  int local_1a8;
  undefined4 *local_1a4;
  int local_1a0;
  int local_19c;
  int local_198;
  int local_194;
  undefined4 *local_190;
  undefined4 *local_18c;
  int local_188;
  int local_184;
  int local_180;
  int local_17c;
  undefined4 local_178;
  int *local_174;
  int local_170;
  int local_16c;
  int *local_168;
  undefined4 *local_164;
  int *local_160;
  float *local_15c;
  undefined4 *local_158;
  int *local_154;
  int *local_150;
  int *local_14c;
  int *local_148;
  int *local_144;
  int *local_140;
  undefined4 *local_13c;
  int *local_138;
  int local_134;
  undefined4 *local_130;
  int local_12c;
  int local_128;
  int local_124;
  int local_120;
  int *local_11c;
  int *local_118;
  undefined4 *local_114;
  undefined4 *local_110;
  undefined4 *local_10c;
  int local_108;
  int local_104;
  int local_100;
  int local_fc;
  undefined4 *local_f8;
  undefined4 *local_f4;
  int local_f0;
  undefined4 *local_ec;
  int local_e8;
  undefined4 *local_e4;
  undefined4 *local_e0;
  undefined4 *local_dc;
  undefined4 *local_d8;
  undefined4 *local_d4;
  undefined4 *local_d0;
  undefined4 *local_cc;
  undefined4 *local_c8;
  undefined4 *local_c4;
  undefined4 *local_c0;
  undefined4 *local_bc;
  undefined4 *local_b8;
  undefined4 *local_b4;
  undefined4 *local_b0;
  undefined4 *local_ac;
  undefined4 *local_a8;
  undefined4 *local_a4;
  undefined4 *local_a0;
  undefined4 *local_9c;
  undefined4 *local_98;
  undefined4 *local_94;
  undefined4 *local_90;
  undefined4 *local_8c;
  undefined4 *local_88;
  int local_84;
  uint local_80;
  int local_7c;
  int local_78;
  int local_74;
  undefined4 *local_70;
  undefined4 *local_6c;
  int *local_68;
  int *local_64;
  undefined4 *local_60;
  int local_5c;
  int local_58;
  undefined4 *local_54;
  int local_50;
  int *local_4c;
  int local_48;
  int local_44;
  undefined4 *local_40;
  int local_3c;
  undefined4 *local_38;
  undefined4 *local_34;
  undefined4 *local_30;
  undefined4 *local_2c;
  undefined4 *local_28;
  undefined4 local_24;
  undefined4 *local_20;
  uint local_1c;
  int local_18;
  int local_14;
  undefined4 local_10;
  undefined4 local_c;
  undefined4 *local_8;
  
  local_20 = (undefined4 *)0x0;
  local_1c = 1;
  local_8 = FUN_0045a724();
  if (param_4 == 1) {
    local_c = 1;
    local_10 = 0;
    local_24 = 4;
    local_2c = (undefined4 *)FUN_00402298(0x60);
    if (local_2c == (undefined4 *)0x0) {
      local_28 = (undefined4 *)0x0;
    }
    else {
      local_28 = FUN_00455de4(local_2c,param_2,1,1,local_8);
    }
  }
  else {
    local_c = 3;
    local_10 = 0xffffffff;
    local_24 = 0;
    local_30 = (undefined4 *)FUN_00402298(0x60);
    if (local_30 == (undefined4 *)0x0) {
      local_28 = (undefined4 *)0x0;
    }
    else {
      local_28 = FUN_00455de4(local_30,param_2,1,0,local_8);
    }
  }
  local_38 = (undefined4 *)FUN_00402298(100);
  if (local_38 == (undefined4 *)0x0) {
    local_34 = (undefined4 *)0x0;
  }
  else {
    local_34 = FUN_00453578(local_38,param_2,3,0,local_8,local_c,local_10);
  }
  FUN_00455c18((int)local_28,local_34);
  if (((param_4 == 1) && (local_3c = FUN_0041bf44(param_2,1), local_3c != 0)) &&
     (local_40 = (undefined4 *)FUN_00402298(0x48), local_40 != (undefined4 *)0x0)) {
    FUN_00453f18(local_40,param_2,2,*(undefined4 *)(param_1 + 300),local_8,local_34[0xb],local_3c,2)
    ;
  }
  if ((*(int *)(param_1 + 0xb0) != 0) && (iVar3 = FUN_00417ab4(param_1 + 0x40), param_2 == iVar3)) {
    local_44 = local_34[0xb];
    FUN_00489cec(local_44,*(int *)(param_1 + 0x120));
  }
  local_48 = param_2;
  local_4c = (int *)FUN_004022b0(*(int *)(param_2 + 0x318) << 2);
  local_50 = FUN_00417ab4(local_48 + 0x31c);
  FUN_0041f216(local_258,local_48 + 0x300);
LAB_004cf86e:
  do {
    iVar3 = (**(code **)(local_258[0] + 0x28))(local_258);
    if (iVar3 == 0) {
      if (param_4 == 1) {
        local_e8 = FUN_0041f98c(param_2,&DAT_0051d2ae);
        if (local_e8 == 0) {
          FUN_004dbb24(&DAT_00524e20,s_Mech_did_not_have_a_HUD_subsyste_0051d36f,(char *)0x0);
        }
        else {
          iVar3 = FUN_0041bfc0(param_2,s_TargetReticle_0051d2b2);
          *(int *)(param_1 + 0x130) = iVar3;
          local_ec = (undefined4 *)FUN_0041bf44(local_e8,8);
          local_f0 = FUN_0041bf44(local_e8,4);
          local_f4 = (undefined4 *)FUN_0041bf44(local_e8,5);
          local_f8 = (undefined4 *)FUN_0041bf44(local_e8,6);
          local_fc = FUN_0041bf44(local_e8,0xd);
          local_100 = FUN_0041bf44(local_e8,0xc);
          local_104 = FUN_0041bf44(local_e8,0xb);
          local_108 = FUN_0041bf44(local_e8,10);
          if (((local_108 == 0) || (*(int *)(param_1 + 0x130) == 0)) ||
             ((local_ec == (undefined4 *)0x0 ||
              ((((local_f0 == 0 || (local_f4 == (undefined4 *)0x0)) ||
                (local_f8 == (undefined4 *)0x0)) || (local_fc == 0)))))) {
            FUN_0040385c(s_Bad_reticle__one_of_TargetReticl_0051d2c0,
                         s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d315,0x7be);
          }
          local_10c = (undefined4 *)FUN_00402298(0x358);
          if (local_10c == (undefined4 *)0x0) {
            local_20 = (undefined4 *)0x0;
          }
          else {
            local_114 = local_f8;
            local_110 = local_f4;
            local_20 = FUN_004cc40c(local_10c,param_2,1,(undefined4 *)(param_1 + 0x130),
                                    *(undefined4 *)(param_1 + 0x124),local_ec,local_fc,local_f0,
                                    *local_f4,*local_f8,0x44960000,0,local_100,local_104,local_108);
          }
          if (local_20 == (undefined4 *)0x0) {
            FUN_0040385c(s_Could_not_create_the_reticle_0051d333,
                         s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d351,0x7d3);
          }
        }
      }
      local_118 = (int *)0x0;
      local_11c = (int *)0x0;
      iVar3 = 0;
      do {
        if (*(int *)(param_2 + 0x124) <= iVar3) {
          if ((local_118 != (int *)0x0) &&
             (local_1cc = (undefined4 *)FUN_00402298(0x2c), local_1cc != (undefined4 *)0x0)) {
            FUN_00456778(local_1cc,param_2,1,local_118,(int)local_11c);
          }
          local_1d4 = (undefined4 *)FUN_00402298(0x14);
          if (local_1d4 == (undefined4 *)0x0) {
            local_1dc = (undefined4 *)0x0;
          }
          else {
            local_1dc = FUN_00460cd0(local_1d4,param_2,(int)local_4c);
          }
          local_1d8 = param_2;
          local_1d0 = local_1dc;
          (**(code **)(*(int *)(param_1 + 0x3a4) + 8))(param_1 + 0x3a4,local_1dc,&local_1d8);
          FUN_004022e8(local_4c);
          local_1e4 = (undefined4 *)FUN_00402298(0x38);
          if (local_1e4 == (undefined4 *)0x0) {
            local_1e0 = (undefined4 *)0x0;
          }
          else {
            local_1e0 = FUN_00455d3c(local_1e4,param_2,3,0x3f000000);
          }
          FUN_00455e88((int)local_28,local_1e0);
          iVar3 = 0;
          do {
            if (*(int *)(param_2 + 0x11c) <= iVar3) {
              uVar14 = local_34[0xb];
              FUN_0041f235(local_258,2);
              return uVar14;
            }
            local_1e8 = *(int *)(*(int *)(param_2 + 0x120) + iVar3 * 4);
            local_1ec = local_24;
            iVar8 = (**(code **)(*(int *)(local_1e8 + 0xbc) + 0xc))(local_1e8 + 0xbc,&local_1ec);
            if (iVar8 != 0) {
              local_1f8 = (undefined4 *)FUN_00402298(0x3c);
              if (local_1f8 == (undefined4 *)0x0) {
                local_1f4 = (undefined4 *)0x0;
              }
              else {
                local_1f4 = FUN_00455c7c(local_1f8,param_2,3,(undefined4 *)(local_1e8 + 0x158),
                                         0x3d23d70a);
              }
              FUN_00455c18((int)local_1e0,local_1f4);
              (**(code **)(**(int **)(iVar8 + 0xc) + 4))(*(int **)(iVar8 + 0xc));
              while( true ) {
                iVar9 = (**(code **)(**(int **)(iVar8 + 0xc) + 0x30))(*(int **)(iVar8 + 0xc));
                if (iVar9 == 0) {
                  local_1f0 = (int *)0x0;
                }
                else {
                  local_1fc = (**(code **)(**(int **)(iVar8 + 0xc) + 0x28))(*(int **)(iVar8 + 0xc));
                  local_1f0 = (int *)(local_1fc + 0xc);
                }
                if (local_1f0 == (int *)0x0) break;
                uVar10 = 0xffffffff;
                pcVar12 = *(char **)(*local_1f0 + 8);
                do {
                  pcVar7 = pcVar12;
                  if (uVar10 == 0) break;
                  uVar10 = uVar10 - 1;
                  pcVar7 = pcVar12 + 1;
                  cVar2 = *pcVar12;
                  pcVar12 = pcVar7;
                } while (cVar2 != '\0');
                uVar10 = ~uVar10;
                pcVar12 = pcVar7 + -uVar10;
                pcVar7 = (char *)&DAT_00524b54;
                for (uVar11 = uVar10 >> 2; uVar11 != 0; uVar11 = uVar11 - 1) {
                  *(undefined4 *)pcVar7 = *(undefined4 *)pcVar12;
                  pcVar12 = pcVar12 + 4;
                  pcVar7 = pcVar7 + 4;
                }
                for (uVar10 = uVar10 & 3; uVar10 != 0; uVar10 = uVar10 - 1) {
                  *pcVar7 = *pcVar12;
                  pcVar12 = pcVar12 + 1;
                  pcVar7 = pcVar7 + 1;
                }
                local_204 = FUN_00497678((char *)&DAT_00524b54,0,&local_200);
                if (local_204 == 0) {
                  FUN_004dbb24(&DAT_00524e20,s_BTL4VideoRenderer__Material_name_0051d6f8,(char *)0x0
                              );
                  FUN_004dbb24(&DAT_00524e20,(char *)&DAT_00524b54,(char *)0x0);
                  FUN_004dbb24(&DAT_00524e20,s_could_not_be_found_0051d71a,(char *)0x0);
                }
                else {
                  FUN_00402a98((int *)&local_208,local_1f0,(char *)&DAT_00524b54);
                  local_20c = local_208;
                  piVar4 = local_208 + 3;
                  *piVar4 = *piVar4 + -1;
                  if (*piVar4 == 0) {
                    FUN_004024d8(local_208,3);
                  }
                  local_214 = (undefined4 *)FUN_00402298(0xe8);
                  if (local_214 == (undefined4 *)0x0) {
                    local_210 = (undefined4 *)0x0;
                  }
                  else {
                    local_210 = FUN_004573e4(local_214,param_2,3,local_204,
                                             (undefined4 *)(local_1e8 + 0x158),0.1);
                  }
                  FUN_00455c18((int)local_1f4,local_210);
                }
              }
            }
            iVar3 = iVar3 + 1;
          } while( true );
        }
        iVar8 = *(int *)(*(int *)(param_2 + 0x128) + iVar3 * 4);
        if (((iVar8 != 0) && (iVar3 != 0)) && (local_120 = *(int *)(iVar8 + 0xdc), local_120 != -1))
        {
          local_124 = local_120;
          FUN_0041f216(local_2c0,local_48 + 0x300);
          iVar9 = (**(code **)(local_2c0[0] + 0x34))(local_2c0,local_124);
          FUN_0041f235(local_2c0,2);
          if (*(int *)(iVar9 + 0xc4) == 0) {
            local_128 = local_34[0xb];
          }
          else {
            local_12c = *(int *)(iVar9 + 200);
            local_128 = local_4c[local_12c];
          }
          local_130 = (undefined4 *)(iVar9 + 0x74);
          puVar5 = local_130;
          puVar6 = local_2f0;
          for (iVar9 = 0xc; iVar9 != 0; iVar9 = iVar9 + -1) {
            *puVar6 = *puVar5;
            puVar5 = puVar5 + 1;
            puVar6 = puVar6 + 1;
          }
          iVar9 = FUN_0041a1a4(**(int **)(iVar8 + 0xc),0x50de2c);
          if (iVar9 == 0) {
            local_14 = 0;
          }
          else {
            local_134 = iVar8;
            FUN_0040b058((int)local_2f0,3,local_2fc);
            local_308 = *(float *)(local_134 + 0xf8);
            local_304 = *(undefined4 *)(local_134 + 0xfc);
            local_300 = *(undefined4 *)(local_134 + 0x100);
            FUN_004085ec(local_2fc,local_2fc,&local_308);
            FUN_0040b0ac((int)local_2f0,3,local_2fc);
            local_13c = (undefined4 *)FUN_00402298(0x10);
            if (local_13c == (undefined4 *)0x0) {
              local_138 = (int *)0x0;
            }
            else {
              local_138 = (int *)FUN_004023f4(local_13c);
            }
            local_138[3] = local_138[3] + 1;
            local_144 = (int *)(local_134 + 0xf4);
            local_148 = (int *)*local_144;
            local_148[3] = local_148[3] + 1;
            FUN_00402a4c((int *)&local_140,(int *)&local_138,(int *)&local_148);
            local_14c = local_140;
            piVar4 = local_140 + 3;
            *piVar4 = *piVar4 + -1;
            if (*piVar4 == 0) {
              FUN_004024d8(local_140,3);
            }
            local_150 = local_148;
            piVar4 = local_148 + 3;
            *piVar4 = *piVar4 + -1;
            if (*piVar4 == 0) {
              FUN_004024d8(local_148,3);
            }
            pcVar7 = &DAT_0051d398;
            pcVar12 = (char *)local_138[2];
            do {
              bVar13 = *pcVar7 == *pcVar12;
              if (!bVar13) break;
              if (*pcVar7 == '\0') goto LAB_004cfd8d;
              pcVar1 = pcVar7 + 1;
              bVar13 = *pcVar1 == pcVar12[1];
              if (!bVar13) break;
              pcVar7 = pcVar7 + 2;
              pcVar12 = pcVar12 + 2;
              bVar13 = *pcVar1 == '\0';
            } while (!bVar13);
            if (bVar13) {
LAB_004cfd8d:
              local_14 = 0;
            }
            else {
              uVar10 = 0xffffffff;
              pcVar12 = (char *)local_138[2];
              do {
                pcVar7 = pcVar12;
                if (uVar10 == 0) break;
                uVar10 = uVar10 - 1;
                pcVar7 = pcVar12 + 1;
                cVar2 = *pcVar12;
                pcVar12 = pcVar7;
              } while (cVar2 != '\0');
              uVar10 = ~uVar10;
              pcVar12 = pcVar7 + -uVar10;
              pcVar7 = local_23c;
              for (uVar11 = uVar10 >> 2; uVar11 != 0; uVar11 = uVar11 - 1) {
                *(undefined4 *)pcVar7 = *(undefined4 *)pcVar12;
                pcVar12 = pcVar12 + 4;
                pcVar7 = pcVar7 + 4;
              }
              for (uVar10 = uVar10 & 3; uVar10 != 0; uVar10 = uVar10 - 1) {
                *pcVar7 = *pcVar12;
                pcVar12 = pcVar12 + 1;
                pcVar7 = pcVar7 + 1;
              }
              local_14 = FUN_00498448(local_23c,local_1c);
            }
            local_154 = local_138;
            piVar4 = local_138 + 3;
            *piVar4 = *piVar4 + -1;
            if (*piVar4 == 0) {
              FUN_004024d8(local_138,3);
            }
          }
          if (((param_4 == 1) &&
              (iVar9 = FUN_0041a1a4(**(int **)(iVar8 + 0xc),0x511830), iVar9 != 0)) &&
             (local_20 != (undefined4 *)0x0)) {
            local_158 = (undefined4 *)FUN_0041bf44(iVar8,0x15);
            local_15c = (float *)FUN_0041bf44(iVar8,0x16);
            local_160 = (int *)FUN_0041bf44(iVar8,0x17);
            local_164 = (undefined4 *)FUN_0041bf44(iVar8,0x18);
            local_168 = (int *)FUN_0041bf44(iVar8,0x19);
            local_16c = FUN_0041bf44(iVar8,1);
            local_170 = FUN_0041bf44(iVar8,0x1c);
            local_174 = (int *)FUN_0041bf44(iVar8,0x1b);
            if (local_158 == (undefined4 *)0x0) {
              FUN_0040385c(s_No_TargetWithinRange_attribute_i_0051d39d,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d3d2,0x866);
            }
            if (local_15c == (float *)0x0) {
              FUN_0040385c(s_No_WeaponRange_attribute_in_weap_0051d3f0,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d41f,0x868);
            }
            if (local_160 == (int *)0x0) {
              FUN_0040385c(s_No_PipPosition_attribute_in_weap_0051d43d,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d46c,0x86a);
            }
            if (local_164 == (undefined4 *)0x0) {
              FUN_0040385c(s_No_PipColor_attribute_in_weapons_0051d48a,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d4b6,0x86c);
            }
            if (local_168 == (int *)0x0) {
              FUN_0040385c(s_No_PipExtendedRange_attribute_in_0051d4d4,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d508,0x86e);
            }
            if (local_16c == 0) {
              FUN_0040385c(s_No_SimulationState_attribute_in_w_0051d526,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d559,0x870);
            }
            if (local_170 == 0) {
              FUN_0040385c(s_No_SimulationState_attribute_in_w_0051d577,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d5aa,0x873);
            }
            if (local_174 == (int *)0x0) {
              FUN_0040385c(s_No_RearFiring_attribute_in_weapo_0051d5c8,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d5f6,0x875);
            }
            if (*local_174 == 0) {
              local_178 = 1;
            }
            else {
              local_178 = 2;
            }
            FUN_004cdac0((int)local_20,*local_15c,*local_160,local_158,*local_168,*local_164,
                         local_164[1],local_164[2],local_170,2,3,local_16c,1,local_178);
          }
          switch(*(undefined4 *)(iVar8 + 4)) {
          case 0xbc0:
            FUN_0040b058((int)local_2f0,3,local_320);
            local_1b0 = FUN_0041bfc0(iVar8,s_ReservoirState_0051d614);
            if (local_1b0 == 0) {
              FUN_0040385c(s_Reservoir_did_not_have_a_Reservo_0051d623,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d64c,0x926);
            }
            local_1b4 = (undefined4 *)FUN_00402298(0x138);
            if (local_1b4 != (undefined4 *)0x0) {
              FUN_00456a68(local_1b4,param_2,2,local_1b0,1,*(undefined4 **)(param_1 + 0x318),
                           local_128,local_320);
            }
            break;
          case 0xbc8:
            local_17c = FUN_0041bf44(iVar8,0x1e);
            local_180 = FUN_0041bf44(iVar8,0x1f);
            local_184 = FUN_0041bf44(iVar8,0x1d);
            local_188 = FUN_0041bf44(iVar8,0x1c);
            local_190 = (undefined4 *)FUN_00402298(0x80);
            if (local_190 == (undefined4 *)0x0) {
              local_18c = (undefined4 *)0x0;
            }
            else {
              local_18c = FUN_004593c0(local_190,param_2,2,local_14,local_8,1,0,local_128,local_2f0,
                                       local_188,0,local_180,local_17c);
            }
            break;
          case 0xbcd:
            FUN_0040b058((int)local_2f0,3,local_314);
            local_1a8 = FUN_0041bf44(iVar8,0x1c);
            if ((param_4 != 1) &&
               (local_1ac = (undefined4 *)FUN_00402298(0x138), local_1ac != (undefined4 *)0x0)) {
              FUN_00456a68(local_1ac,param_2,2,local_1a8,0,*(undefined4 **)(param_1 + 0x2e4),
                           local_128,local_314);
            }
            break;
          case 0xbd4:
            local_194 = FUN_0041bf44(iVar8,0x1e);
            local_198 = FUN_0041bf44(iVar8,0x1f);
            local_19c = FUN_0041bf44(iVar8,0x1d);
            local_1a0 = FUN_0041bf44(iVar8,0x1c);
            local_1a4 = (undefined4 *)FUN_00402298(0x88);
            if (local_1a4 != (undefined4 *)0x0) {
              FUN_004590d8(local_1a4,param_2,2,local_14,local_8,1,0,local_128,local_2f0,local_1a0,0,
                           local_198,local_194,0x40000000);
            }
            break;
          case 0xbd8:
            local_1b8 = (int *)FUN_0041bfc0(iVar8,s_LightOn_0051d66a);
            if (local_1b8 == (int *)0x0) {
              FUN_0040385c(s_searchlight_subsystem_had_no_lig_0051d672,
                           s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d6a2,0x941);
            }
            if (param_4 == 1) {
              if (local_118 == (int *)0x0) {
                local_118 = local_1b8;
              }
              else {
                local_11c = local_1b8;
              }
            }
            else {
              local_1bc = FUN_00498448(s_spot_bgf_0051d6c0,0);
              if (local_1bc == 0) {
                FUN_004dbb24(&DAT_00524e20,s_Couldn_t_locate_spot_bgf_for_mec_0051d6c9,(char *)0x0);
              }
              else {
                local_1c4 = (undefined4 *)FUN_00402298(0x50);
                if (local_1c4 == (undefined4 *)0x0) {
                  local_1c0 = (undefined4 *)0x0;
                }
                else {
                  local_1c0 = FUN_0045848c(local_1c4,param_2,(int)local_8,local_1bc,1,0,local_2f0,
                                           local_128);
                }
                local_1c8 = (undefined4 *)FUN_00402298(0x2c);
                if (local_1c8 != (undefined4 *)0x0) {
                  FUN_0045612c(local_1c8,param_2,1,local_1c0[6],1,local_1b8);
                }
              }
            }
          }
        }
        iVar3 = iVar3 + 1;
      } while( true );
    }
    FUN_0040aadc(local_288);
    local_54 = (undefined4 *)(iVar3 + 0x74);
    FUN_0040ab28(local_288,local_54);
    if (*(int *)(iVar3 + 0xc4) == 0) {
      local_58 = local_34[0xb];
    }
    else {
      local_5c = *(int *)(iVar3 + 200);
      local_58 = local_4c[local_5c];
    }
    if (*(int *)(iVar3 + 0x10) != 0) {
      if (param_4 == 1) {
        local_60 = (undefined4 *)(iVar3 + 0x11c);
        local_68 = (int *)*local_60;
        pcVar7 = s_siteeyepoint_0051d290;
        local_68[3] = local_68[3] + 1;
        pcVar12 = (char *)local_68[2];
        do {
          bVar13 = *pcVar12 == *pcVar7;
          if ((!bVar13) || (bVar13 = true, *pcVar12 == '\0')) break;
          pcVar1 = pcVar12 + 1;
          bVar13 = *pcVar1 == pcVar7[1];
          if (!bVar13) break;
          pcVar12 = pcVar12 + 2;
          pcVar7 = pcVar7 + 2;
          bVar13 = *pcVar1 == '\0';
        } while (!bVar13);
        uVar10 = (uint)bVar13;
        piVar4 = local_68 + 3;
        *piVar4 = *piVar4 + -1;
        local_64 = local_68;
        if (*piVar4 == 0) {
          FUN_004024d8(local_68,3);
        }
        if (uVar10 != 0) {
          local_6c = (undefined4 *)FUN_0041bfc0(param_2,s_EyepointRotation_0051d29d);
          local_70 = (undefined4 *)FUN_00402298(0x5c);
          if (local_70 != (undefined4 *)0x0) {
            FUN_004579a8(local_70,param_2,(int)local_8,local_288,local_58,
                         *(undefined4 **)(param_1 + 0x124),local_6c);
          }
        }
      }
      goto LAB_004cf86e;
    }
    piVar4 = (int *)FUN_00424084(iVar3,local_24);
    if (piVar4 == (int *)0x0) {
      local_14 = 0;
    }
    else {
      uVar10 = 0xffffffff;
      pcVar12 = *(char **)(*piVar4 + 8);
      do {
        pcVar7 = pcVar12;
        if (uVar10 == 0) break;
        uVar10 = uVar10 - 1;
        pcVar7 = pcVar12 + 1;
        cVar2 = *pcVar12;
        pcVar12 = pcVar7;
      } while (cVar2 != '\0');
      uVar10 = ~uVar10;
      pcVar12 = pcVar7 + -uVar10;
      pcVar7 = local_23c;
      for (uVar11 = uVar10 >> 2; uVar11 != 0; uVar11 = uVar11 - 1) {
        *(undefined4 *)pcVar7 = *(undefined4 *)pcVar12;
        pcVar12 = pcVar12 + 4;
        pcVar7 = pcVar7 + 4;
      }
      for (uVar10 = uVar10 & 3; uVar10 != 0; uVar10 = uVar10 - 1) {
        *pcVar7 = *pcVar12;
        pcVar12 = pcVar12 + 1;
        pcVar7 = pcVar7 + 1;
      }
      local_14 = FUN_00498448(local_23c,local_1c);
    }
    piVar4 = (int *)FUN_00424084(iVar3,local_24);
    if (piVar4 == (int *)0x0) {
      local_18 = 0;
      local_74 = 0;
    }
    else {
      uVar10 = 0xffffffff;
      pcVar12 = *(char **)(*piVar4 + 8);
      do {
        pcVar7 = pcVar12;
        if (uVar10 == 0) break;
        uVar10 = uVar10 - 1;
        pcVar7 = pcVar12 + 1;
        cVar2 = *pcVar12;
        pcVar12 = pcVar7;
      } while (cVar2 != '\0');
      uVar10 = ~uVar10;
      pcVar12 = pcVar7 + -uVar10;
      pcVar7 = local_23c;
      for (uVar11 = uVar10 >> 2; uVar11 != 0; uVar11 = uVar11 - 1) {
        *(undefined4 *)pcVar7 = *(undefined4 *)pcVar12;
        pcVar12 = pcVar12 + 4;
        pcVar7 = pcVar7 + 4;
      }
      for (uVar10 = uVar10 & 3; uVar10 != 0; uVar10 = uVar10 - 1) {
        *pcVar7 = *pcVar12;
        pcVar12 = pcVar12 + 1;
        pcVar7 = pcVar7 + 1;
      }
      local_18 = FUN_00498448(local_23c,local_1c);
      local_78 = *(int *)(*(int *)(param_2 + 0x120) + *(int *)(iVar3 + 0x100) * 4);
      local_74 = local_78 + 100;
    }
    local_7c = *(int *)(iVar3 + 0xcc);
    iVar8 = 0;
    if (*(int *)(iVar3 + 0xc0) == -1) {
      local_80 = 3;
    }
    else {
      local_84 = *(int *)(iVar3 + 0xc0);
      FUN_0041d3b3(local_2a4,local_50 + 0xe4);
      iVar8 = (**(code **)(local_2a4[0] + 0x34))(local_2a4,local_84);
      FUN_0041d3d2(local_2a4,2);
      local_80 = *(uint *)(iVar8 + 0x10);
    }
    if (2 < local_80) {
      if (local_80 != 3) {
        if (local_80 == 4) {
          local_a4 = (undefined4 *)FUN_00402298(0x7c);
          if (local_a4 == (undefined4 *)0x0) {
            local_a0 = (undefined4 *)0x0;
          }
          else {
            puVar5 = (undefined4 *)FUN_0041cfa0(iVar8);
            local_a0 = FUN_004539b4(local_a4,param_2,3,local_14,local_8,local_c,local_10,local_58,
                                    local_288,puVar5);
          }
          FUN_00455e88((int)local_28,local_a0);
          local_4c[local_7c] = local_a0[0xb];
          if (local_18 != 0) {
            local_ac = (undefined4 *)FUN_00402298(0x30);
            if (local_ac == (undefined4 *)0x0) {
              local_a8 = (undefined4 *)0x0;
            }
            else {
              local_a8 = FUN_00453474(local_ac,param_2,0,local_18,local_a0[0xb],local_c,local_10,1);
            }
            local_b0 = (undefined4 *)FUN_00402298(0x30);
            if (local_b0 != (undefined4 *)0x0) {
              FUN_00456224(local_b0,param_2,2,local_a0[0xc],1,local_74,0);
            }
            local_b4 = (undefined4 *)FUN_00402298(0x30);
            if (local_b4 != (undefined4 *)0x0) {
              FUN_00456224(local_b4,param_2,2,local_a8[0xb],1,local_74,1);
            }
          }
          goto LAB_004cf86e;
        }
        if (local_80 == 5) {
          local_bc = (undefined4 *)FUN_00402298(0x8c);
          if (local_bc == (undefined4 *)0x0) {
            local_b8 = (undefined4 *)0x0;
          }
          else {
            puVar5 = *(undefined4 **)(iVar8 + 0xc);
            puVar6 = (undefined4 *)FUN_0041cfa0(iVar8);
            local_b8 = FUN_00453ac4(local_bc,param_2,3,local_14,local_8,local_c,local_10,local_58,
                                    local_288,puVar6,puVar5);
          }
          FUN_00455e88((int)local_28,local_b8);
          local_4c[local_7c] = local_b8[0xb];
          if (local_18 != 0) {
            local_c4 = (undefined4 *)FUN_00402298(0x30);
            if (local_c4 == (undefined4 *)0x0) {
              local_c0 = (undefined4 *)0x0;
            }
            else {
              local_c0 = FUN_00453474(local_c4,param_2,0,local_18,local_b8[0xb],local_c,local_10,1);
            }
            local_c8 = (undefined4 *)FUN_00402298(0x30);
            if (local_c8 != (undefined4 *)0x0) {
              FUN_00456224(local_c8,param_2,2,local_b8[0xc],1,local_74,0);
            }
            local_cc = (undefined4 *)FUN_00402298(0x30);
            if (local_cc != (undefined4 *)0x0) {
              FUN_00456224(local_cc,param_2,2,local_c0[0xb],1,local_74,1);
            }
          }
          goto LAB_004cf86e;
        }
      }
      local_d4 = (undefined4 *)FUN_00402298(0x50);
      if (local_d4 == (undefined4 *)0x0) {
        local_d0 = (undefined4 *)0x0;
      }
      else {
        local_d0 = FUN_0045848c(local_d4,param_2,(int)local_8,local_14,local_c,local_10,local_288,
                                local_58);
      }
      local_4c[local_7c] = local_d0[4];
      if (local_18 != 0) {
        local_dc = (undefined4 *)FUN_00402298(0x30);
        if (local_dc == (undefined4 *)0x0) {
          local_d8 = (undefined4 *)0x0;
        }
        else {
          local_d8 = FUN_00453474(local_dc,param_2,0,local_18,local_d0[4],local_c,local_10,1);
        }
        local_e0 = (undefined4 *)FUN_00402298(0x30);
        if (local_e0 != (undefined4 *)0x0) {
          FUN_00456224(local_e0,param_2,2,local_d0[6],1,local_74,0);
        }
        local_e4 = (undefined4 *)FUN_00402298(0x30);
        if (local_e4 != (undefined4 *)0x0) {
          FUN_00456224(local_e4,param_2,2,local_d8[0xb],1,local_74,1);
        }
      }
      goto LAB_004cf86e;
    }
    local_8c = (undefined4 *)FUN_00402298(0x78);
    if (local_8c == (undefined4 *)0x0) {
      local_88 = (undefined4 *)0x0;
    }
    else {
      local_88 = FUN_004537e8(local_8c,param_2,3,local_14,local_8,local_c,local_10,local_58,
                              local_288,*(undefined4 **)(iVar8 + 0xc));
    }
    FUN_00455e88((int)local_28,local_88);
    local_4c[local_7c] = local_88[0xb];
    if (local_18 != 0) {
      local_94 = (undefined4 *)FUN_00402298(0x30);
      if (local_94 == (undefined4 *)0x0) {
        local_90 = (undefined4 *)0x0;
      }
      else {
        local_90 = FUN_00453474(local_94,param_2,0,local_18,local_88[0xb],local_c,local_10,1);
      }
      local_98 = (undefined4 *)FUN_00402298(0x30);
      if (local_98 != (undefined4 *)0x0) {
        FUN_00456224(local_98,param_2,2,local_88[0xc],1,local_74,0);
      }
      local_9c = (undefined4 *)FUN_00402298(0x30);
      if (local_9c != (undefined4 *)0x0) {
        FUN_00456224(local_9c,param_2,2,local_90[0xb],1,local_74,1);
      }
    }
  } while( true );
}



/* ---- @ 004d0cc0 ---- */

void __cdecl FUN_004d0cc0(undefined4 param_1,int param_2)

{
  char cVar1;
  int iVar2;
  int iVar3;
  int *piVar4;
  int *piVar5;
  char *pcVar6;
  char *pcVar7;
  uint uVar8;
  uint uVar9;
  char *pcVar10;
  char *pcVar11;
  char local_7c [80];
  char *local_2c;
  char *local_28;
  char *local_24;
  undefined4 *local_20;
  uint local_1c;
  char *local_18;
  char *local_14;
  char *local_10;
  undefined4 *local_c;
  int *local_8;
  
  if (DAT_0051d19c == '\0') {
    DAT_0051d198 = FUN_004d4a78(PTR_s__color__0051d188);
    DAT_0051d19c = DAT_0051d19c + '\x01';
  }
  if (DAT_0051d1a4 == '\0') {
    DAT_0051d1a0 = FUN_004d4a78(PTR_s__badge__0051d18c);
    DAT_0051d1a4 = DAT_0051d1a4 + '\x01';
  }
  if (DAT_0051d1ac == '\0') {
    DAT_0051d1a8 = FUN_004d4a78(PTR_s__patch__0051d190);
    DAT_0051d1ac = DAT_0051d1ac + '\x01';
  }
  if (DAT_0051d1b4 == '\0') {
    DAT_0051d1b0 = FUN_004d4a78(PTR_s__serno__0051d194);
    DAT_0051d1b4 = DAT_0051d1b4 + '\x01';
  }
  iVar3 = FUN_00406ff8(*(int *)(DAT_004efc94 + 0x68),s_vehicletable_0051d941,0x19,-1);
  if (iVar3 != 0) {
    iVar2 = *(int *)(iVar3 + 4);
    *(int *)(iVar3 + 4) = *(int *)(iVar3 + 4) + 1;
    if (iVar2 == 0) {
      FUN_00406cd0(iVar3);
    }
    local_20 = *(undefined4 **)(iVar3 + 0x3c);
    uVar8 = *(uint *)(iVar3 + 0x40);
    piVar4 = (int *)FUN_004022b0(uVar8);
    FUN_004d4918(piVar4,local_20,uVar8);
    *(int *)(iVar3 + 4) = *(int *)(iVar3 + 4) + -1;
    piVar5 = (int *)FUN_00402298(0x20);
    if (piVar5 == (int *)0x0) {
      local_8 = (int *)0x0;
    }
    else {
      local_8 = FUN_00403e84(piVar5,(char *)0x0,1);
    }
    FUN_00404d00((int)local_8,(char *)piVar4,uVar8);
    FUN_004022d0(piVar4);
    pcVar11 = *(char **)(*(int *)(param_2 + 0x848) + 8);
    pcVar7 = *(char **)(*(int *)(param_2 + 0x844) + 8);
    pcVar6 = *(char **)(*(int *)(param_2 + 0x84c) + 8);
    iVar3 = FUN_00404088((int)local_8,s_color_0051d94e,pcVar11,&local_10);
    if (iVar3 == 0) {
      local_24 = pcVar11;
      FUN_004dbb24(&DAT_00524e20,s_____Color_value___0051d954,(char *)0x0);
      FUN_004dbb24(&DAT_00524e20,local_24,(char *)0x0);
      FUN_004dbb24(&DAT_00524e20,s___from_egg_not_found_in_vehicle_t_0051d966,(char *)0x0);
      FUN_004d9c38(&DAT_00524e20);
      FUN_0040385c(s_Exiting__0051d991,s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051d99a,0xbeb);
    }
    iVar3 = FUN_00404088((int)local_8,s_badge_0051d9b8,pcVar7,&local_14);
    if (iVar3 == 0) {
      local_28 = pcVar7;
      FUN_004dbb24(&DAT_00524e20,s_____Badge_value___0051d9be,(char *)0x0);
      FUN_004dbb24(&DAT_00524e20,local_28,(char *)0x0);
      FUN_004dbb24(&DAT_00524e20,s___from_egg_not_found_in_vehicle_t_0051d9d0,(char *)0x0);
      FUN_004d9c38(&DAT_00524e20);
      FUN_0040385c(s_Exiting__0051d9fb,s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051da04,0xbf2);
    }
    iVar3 = FUN_00404088((int)local_8,s_patch_0051da22,pcVar6,&local_18);
    if (iVar3 == 0) {
      local_2c = pcVar6;
      FUN_004dbb24(&DAT_00524e20,s_____Patch_value___0051da28,(char *)0x0);
      FUN_004dbb24(&DAT_00524e20,local_2c,(char *)0x0);
      FUN_004dbb24(&DAT_00524e20,s___from_egg_not_found_in_vehicle_t_0051da3a,(char *)0x0);
      FUN_004d9c38(&DAT_00524e20);
      FUN_0040385c(s_Exiting__0051da65,s_d__tesla_bt_bt_l4_BTL4VID_CPP_0051da6e,0xbf9);
    }
    DAT_004f1aac = FUN_00404720((int)local_8,s_substitute_0051da8c,(char *)0x0);
    for (local_c = (undefined4 *)DAT_004f1aac[1]; local_c != (undefined4 *)0x0;
        local_c = (undefined4 *)*local_c) {
      pcVar11 = local_7c;
      pcVar7 = (char *)local_c[1];
      local_7c[0] = '\0';
      while (pcVar6 = FUN_004d49f4(pcVar7,'%'), pcVar6 != (char *)0x0) {
        local_1c = (int)pcVar6 - (int)pcVar7;
        pcVar10 = pcVar7;
        if (local_1c != 0) {
          FUN_004d4b9c((undefined4 *)pcVar11,pcVar7,local_1c);
          pcVar11 = pcVar11 + local_1c;
          pcVar10 = pcVar6;
        }
        iVar3 = FUN_004d4ae0(pcVar6,PTR_s__serno__0051d194,DAT_0051d1b0);
        if (iVar3 == 0) {
          if (s_0GraphicGaugeBackground_0051d1b5[0] != '\0') {
            *pcVar11 = s_0GraphicGaugeBackground_0051d1b5[0];
            pcVar11 = pcVar11 + 1;
          }
          pcVar7 = pcVar10 + DAT_0051d1b0;
        }
        else {
          iVar3 = FUN_004d4ae0(pcVar6,PTR_s__color__0051d188,DAT_0051d198);
          if (iVar3 == 0) {
            if (local_10 != (char *)0x0) {
              uVar8 = 0xffffffff;
              pcVar7 = local_10;
              do {
                pcVar6 = pcVar7;
                if (uVar8 == 0) break;
                uVar8 = uVar8 - 1;
                pcVar6 = pcVar7 + 1;
                cVar1 = *pcVar7;
                pcVar7 = pcVar6;
              } while (cVar1 != '\0');
              uVar8 = ~uVar8;
              pcVar7 = pcVar6 + -uVar8;
              pcVar6 = pcVar11;
              for (uVar9 = uVar8 >> 2; uVar9 != 0; uVar9 = uVar9 - 1) {
                *(undefined4 *)pcVar6 = *(undefined4 *)pcVar7;
                pcVar7 = pcVar7 + 4;
                pcVar6 = pcVar6 + 4;
              }
              for (uVar8 = uVar8 & 3; uVar8 != 0; uVar8 = uVar8 - 1) {
                *pcVar6 = *pcVar7;
                pcVar7 = pcVar7 + 1;
                pcVar6 = pcVar6 + 1;
              }
              iVar3 = FUN_004d4a78(local_10);
              pcVar11 = pcVar11 + iVar3;
            }
            pcVar7 = pcVar10 + DAT_0051d198;
          }
          else {
            iVar3 = FUN_004d4ae0(pcVar6,PTR_s__badge__0051d18c,DAT_0051d1a0);
            if (iVar3 == 0) {
              if (local_14 != (char *)0x0) {
                uVar8 = 0xffffffff;
                pcVar7 = local_14;
                do {
                  pcVar6 = pcVar7;
                  if (uVar8 == 0) break;
                  uVar8 = uVar8 - 1;
                  pcVar6 = pcVar7 + 1;
                  cVar1 = *pcVar7;
                  pcVar7 = pcVar6;
                } while (cVar1 != '\0');
                uVar8 = ~uVar8;
                pcVar7 = pcVar6 + -uVar8;
                pcVar6 = pcVar11;
                for (uVar9 = uVar8 >> 2; uVar9 != 0; uVar9 = uVar9 - 1) {
                  *(undefined4 *)pcVar6 = *(undefined4 *)pcVar7;
                  pcVar7 = pcVar7 + 4;
                  pcVar6 = pcVar6 + 4;
                }
                for (uVar8 = uVar8 & 3; uVar8 != 0; uVar8 = uVar8 - 1) {
                  *pcVar6 = *pcVar7;
                  pcVar7 = pcVar7 + 1;
                  pcVar6 = pcVar6 + 1;
                }
                iVar3 = FUN_004d4a78(local_14);
                pcVar11 = pcVar11 + iVar3;
              }
              pcVar7 = pcVar10 + DAT_0051d1a0;
            }
            else {
              iVar3 = FUN_004d4ae0(pcVar6,PTR_s__patch__0051d190,DAT_0051d1a8);
              if (iVar3 == 0) {
                if (local_18 != (char *)0x0) {
                  uVar8 = 0xffffffff;
                  pcVar7 = local_18;
                  do {
                    pcVar6 = pcVar7;
                    if (uVar8 == 0) break;
                    uVar8 = uVar8 - 1;
                    pcVar6 = pcVar7 + 1;
                    cVar1 = *pcVar7;
                    pcVar7 = pcVar6;
                  } while (cVar1 != '\0');
                  uVar8 = ~uVar8;
                  pcVar7 = pcVar6 + -uVar8;
                  pcVar6 = pcVar11;
                  for (uVar9 = uVar8 >> 2; uVar9 != 0; uVar9 = uVar9 - 1) {
                    *(undefined4 *)pcVar6 = *(undefined4 *)pcVar7;
                    pcVar7 = pcVar7 + 4;
                    pcVar6 = pcVar6 + 4;
                  }
                  for (uVar8 = uVar8 & 3; uVar8 != 0; uVar8 = uVar8 - 1) {
                    *pcVar6 = *pcVar7;
                    pcVar7 = pcVar7 + 1;
                    pcVar6 = pcVar6 + 1;
                  }
                  iVar3 = FUN_004d4a78(local_18);
                  pcVar11 = pcVar11 + iVar3;
                }
                pcVar7 = pcVar10 + DAT_0051d1a8;
              }
              else {
                pcVar7 = pcVar10 + 1;
                *pcVar11 = *pcVar10;
                pcVar11 = pcVar11 + 1;
              }
            }
          }
        }
      }
      if (*pcVar7 == '\0') {
        *pcVar11 = '\0';
      }
      else {
        uVar8 = 0xffffffff;
        do {
          pcVar6 = pcVar7;
          if (uVar8 == 0) break;
          uVar8 = uVar8 - 1;
          pcVar6 = pcVar7 + 1;
          cVar1 = *pcVar7;
          pcVar7 = pcVar6;
        } while (cVar1 != '\0');
        uVar8 = ~uVar8;
        pcVar7 = pcVar6 + -uVar8;
        for (uVar9 = uVar8 >> 2; uVar9 != 0; uVar9 = uVar9 - 1) {
          *(undefined4 *)pcVar11 = *(undefined4 *)pcVar7;
          pcVar7 = pcVar7 + 4;
          pcVar11 = pcVar11 + 4;
        }
        for (uVar8 = uVar8 & 3; uVar8 != 0; uVar8 = uVar8 - 1) {
          *pcVar11 = *pcVar7;
          pcVar7 = pcVar7 + 1;
          pcVar11 = pcVar11 + 1;
        }
      }
      iVar3 = FUN_004d4a78(local_7c);
      pcVar7 = (char *)FUN_004022b0(iVar3 + 1);
      uVar8 = 0xffffffff;
      pcVar11 = local_7c;
      do {
        pcVar6 = pcVar11;
        if (uVar8 == 0) break;
        uVar8 = uVar8 - 1;
        pcVar6 = pcVar11 + 1;
        cVar1 = *pcVar11;
        pcVar11 = pcVar6;
      } while (cVar1 != '\0');
      uVar8 = ~uVar8;
      pcVar11 = pcVar6 + -uVar8;
      pcVar6 = pcVar7;
      for (uVar9 = uVar8 >> 2; uVar9 != 0; uVar9 = uVar9 - 1) {
        *(undefined4 *)pcVar6 = *(undefined4 *)pcVar11;
        pcVar11 = pcVar11 + 4;
        pcVar6 = pcVar6 + 4;
      }
      for (uVar8 = uVar8 & 3; uVar8 != 0; uVar8 = uVar8 - 1) {
        *pcVar6 = *pcVar11;
        pcVar11 = pcVar11 + 1;
        pcVar6 = pcVar6 + 1;
      }
      local_c[1] = pcVar7;
    }
    FUN_00403ecc(local_8,3);
    if (s_0GraphicGaugeBackground_0051d1b5[0] == '9') {
      s_0GraphicGaugeBackground_0051d1b5[0] = 'A';
    }
    else {
      s_0GraphicGaugeBackground_0051d1b5[0] = s_0GraphicGaugeBackground_0051d1b5[0] + '\x01';
    }
    FUN_0049664c(FUN_00459eb8);
  }
  return;
}



