/* WARNING: Removing unreachable block (ram,0x004039f4) */
/* WARNING: Removing unreachable block (ram,0x00403a78) */
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void FUN_004038c0(int param_1)

{
  bool bVar1;
  byte bVar2;
  int iVar3;
  undefined4 uVar4;
  uint uVar5;
  int iVar6;
  int iVar7;
  time_t tStack_40;
  tm local_3c;
  
  bVar1 = svc_schedule == 0;
  *(undefined4 *)(param_1 + 0x18) = 0;
  if (bVar1) {
    iVar6 = 0x15180;
    uVar5 = 1;
  }
  else {
    time(&tStack_40);
    tzset();
    localtime_r(&tStack_40,&local_3c);
    iVar3 = (*(int *)(param_1 + 0x28) * 0x3c + *(int *)(param_1 + 0x2c)) * 0x3c;
    iVar7 = (*(int *)(param_1 + 0x20) * 0x3c + *(int *)(param_1 + 0x24)) * 0x3c;
    local_3c.tm_sec = (local_3c.tm_hour * 0x3c + local_3c.tm_min) * 0x3c + local_3c.tm_sec;
    if ((((*(int *)(param_1 + 0x34) == 1) && (iVar3 < iVar7)) && (local_3c.tm_sec < iVar3)) &&
       ((((int)(uint)*(byte *)(param_1 + 0x1c) >> ((int)(local_3c.tm_wday + 6U) % 7 & 0x1fU) & 1U)
         != 0 && (iVar6 = iVar3 - local_3c.tm_sec, -1 < (char)*(byte *)(param_1 + 0x1c))))) {
      uVar5 = (uint)(*(int *)(param_1 + 0x30) != 0);
    }
    else {
      bVar2 = *(byte *)(param_1 + 0x1c);
      if (((int)(uint)bVar2 >> (local_3c.tm_wday & 0x1fU) & 1U) == 0) {
        iVar7 = *(int *)(param_1 + 0x30);
      }
      else {
        if ((*(int *)(param_1 + 0x34) == 1) && (iVar3 < iVar7)) {
          if (((int)(uint)bVar2 >> ((int)(local_3c.tm_wday + 1U) % 7 & 0x1fU) & 1U) == 0) {
            *(byte *)(param_1 + 0x1c) = bVar2 & 0x7f;
            iVar3 = 0x15180;
          }
          else {
            iVar3 = iVar3 + 0x15180;
            *(byte *)(param_1 + 0x1c) = bVar2 | 0x80;
          }
        }
        if (local_3c.tm_sec < iVar7) {
          iVar6 = iVar7 - local_3c.tm_sec;
          uVar5 = (uint)(*(int *)(param_1 + 0x30) == 0);
          goto LAB_00403af8;
        }
        iVar7 = *(int *)(param_1 + 0x30);
        if (local_3c.tm_sec < iVar3) {
          iVar6 = iVar3 - local_3c.tm_sec;
          uVar5 = (uint)(iVar7 != 0);
          goto LAB_00403af8;
        }
      }
      iVar6 = 0x15180 - local_3c.tm_sec;
      uVar5 = (uint)(iVar7 == 0);
    }
  }
LAB_00403af8:
  if (((uVar5 != *(uint *)(param_1 + 0x10)) && (iVar3 = FUN_004036b8(param_1), iVar3 < 0)) ||
     (iVar6 < 1)) {
    iVar6 = 1;
  }
  fprintf(_stderr,"SERVD: service [%s] will be checked in %d sec.\n",*(undefined4 *)(param_1 + 8),
          iVar6);
  uVar4 = sloop_register_timeout(iVar6,0,FUN_004038c0,param_1);
  *(undefined4 *)(param_1 + 0x18) = uVar4;
  return;
}