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

/* ---- @ 004b0f74 ---- */

int * __cdecl
FUN_004b0f74(int *param_1,int param_2,undefined4 param_3,char *param_4,undefined4 param_5,
            int param_6,int param_7)

{
  char cVar1;
  uint uVar2;
  uint uVar3;
  int *piVar4;
  char *pcVar5;
  char *pcVar6;
  int *piVar7;
  int local_8;
  
  FUN_004adda0(param_1,param_2,param_3,param_4,param_5,param_6,param_7);
  *param_1 = (int)&PTR_FUN_0050f9d8;
  FUN_004b1bb1(param_1 + 0x74,0);
  FUN_0041b9ec(param_1 + 0x99,5);
  FUN_0041b9ec(param_1 + 0xae,3);
  local_8 = 0;
  if (*(int *)(param_4 + 0xfc) < *(int *)(param_2 + 0x124)) {
    local_8 = *(int *)(*(int *)(param_2 + 0x128) + *(int *)(param_4 + 0xfc) * 4);
  }
  else {
    FUN_0040385c(s_Bad_voltageSourceIndex_to_connec_0050f700,s_d__tesla_bt_bt_POWERSUB_CPP_0050f72d,
                 0x264);
  }
  if (((*(uint *)(param_2 + 0x28) & 0xc) == 0) && ((*(uint *)(param_2 + 0x28) & 0x100) != 0)) {
    param_1[7] = (int)PTR_FUN_0050f5b0;
    param_1[8] = DAT_0050f5b4;
    param_1[9] = DAT_0050f5b8;
    if (local_8 == 0) {
      FUN_0040385c(s_Master_PoweredSubsystem_is_missi_0050f749,
                   s_d__tesla_bt_bt_POWERSUB_CPP_0050f780,0x272);
    }
    else {
      FUN_004b0dd8((int)param_1,local_8);
    }
  }
  else if (((*(uint *)(param_2 + 0x28) & 0xc) == 4) && (local_8 != 0)) {
    FUN_004b0dd8((int)param_1,local_8);
  }
  param_1[0xc3] = *(int *)(param_4 + 0x100);
  param_1[0xc5] = *(int *)(param_4 + 0x18c);
  param_1[0xc6] = param_1[0xc5];
  FUN_0041bbd8((int)(param_1 + 0x99),4);
  FUN_0041bbd8((int)(param_1 + 0xae),1);
  param_1[0xc4] = 0x3f800000;
  param_1[0x77] = *(int *)(param_4 + 0x104);
  param_1[0x78] = *(int *)(param_4 + 0x108);
  uVar2 = 0xffffffff;
  pcVar5 = param_4 + 0x10c;
  do {
    pcVar6 = pcVar5;
    if (uVar2 == 0) break;
    uVar2 = uVar2 - 1;
    pcVar6 = pcVar5 + 1;
    cVar1 = *pcVar5;
    pcVar5 = pcVar6;
  } while (cVar1 != '\0');
  uVar2 = ~uVar2;
  piVar4 = (int *)(pcVar6 + -uVar2);
  piVar7 = param_1 + 0x79;
  for (uVar3 = uVar2 >> 2; uVar3 != 0; uVar3 = uVar3 - 1) {
    *piVar7 = *piVar4;
    piVar4 = piVar4 + 1;
    piVar7 = piVar7 + 1;
  }
  for (uVar2 = uVar2 & 3; uVar2 != 0; uVar2 = uVar2 - 1) {
    *(char *)piVar7 = (char)*piVar4;
    piVar4 = (int *)((int)piVar4 + 1);
    piVar7 = (int *)((int)piVar7 + 1);
  }
  uVar2 = 0xffffffff;
  pcVar5 = param_4 + 0x14c;
  do {
    pcVar6 = pcVar5;
    if (uVar2 == 0) break;
    uVar2 = uVar2 - 1;
    pcVar6 = pcVar5 + 1;
    cVar1 = *pcVar5;
    pcVar5 = pcVar6;
  } while (cVar1 != '\0');
  uVar2 = ~uVar2;
  piVar4 = (int *)(pcVar6 + -uVar2);
  piVar7 = param_1 + 0x89;
  for (uVar3 = uVar2 >> 2; uVar3 != 0; uVar3 = uVar3 - 1) {
    *piVar7 = *piVar4;
    piVar4 = piVar4 + 1;
    piVar7 = piVar7 + 1;
  }
  for (uVar2 = uVar2 & 3; uVar2 != 0; uVar2 = uVar2 - 1) {
    *(char *)piVar7 = (char)*piVar4;
    piVar4 = (int *)((int)piVar4 + 1);
    piVar7 = (int *)((int)piVar7 + 1);
  }
  return param_1;
}



