clean up the following decompiled C code, using context clues to properly name variables and define structures: 
/* WARNING: Function: _guard_dispatch_icall replaced with injection: guard_dispatch_icall */
/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

void IppReceiveHeadersHelper
               (longlong param_1,undefined1 *param_2,longlong param_3,longlong param_4,
               longlong param_5,longlong param_6)

{
  short *psVar1;
  ushort uVar2;
  longlong **pplVar3;
  undefined8 uVar4;
  int *piVar5;
  char cVar6;
  int iVar7;
  int iVar8;
  longlong lVar9;
  ulonglong uVar10;
  longlong **pplVar11;
  longlong lVar12;
  uint uVar13;
  undefined4 uVar14;
  byte *pbVar15;
  longlong lVar16;
  undefined8 uVar17;
  uint uVar18;
  longlong lVar19;
  longlong unaff_GS_OFFSET;
  undefined auStack_118 [32];
  undefined4 local_f8;
  undefined8 local_f0;
  uint local_e8;
  undefined8 local_e0;
  longlong local_d8;
  byte local_c8;
  byte local_c7;
  uint local_c4;
  int *local_c0;
  longlong **local_b8;
  undefined1 *local_b0;
  longlong local_a8;
  longlong local_a0;
  longlong local_98;
  longlong local_90;
  undefined local_88 [16];
  undefined4 local_78;
  undefined local_70 [16];
  undefined4 local_60;
  ulonglong local_58;
  
  local_58 = __security_cookie ^ (ulonglong)auStack_118;
  lVar16 = *(longlong *)(param_1 + 8);
  uVar18 = (uint)*(ushort *)(param_2 + 0x28);
  local_a8 = param_5;
  lVar19 = *(longlong *)(lVar16 + 8);
  lVar9 = *(longlong *)(lVar19 + 8);
  local_a0 = param_6;
  local_b0 = param_2;
  local_98 = param_4;
  local_90 = param_3;
  if ((*(byte *)(lVar9 + 10) & 5) == 0) {
    local_f0 = CONCAT44(local_f0._4_4_,0x40000000);
    local_f8 = 0;
    lVar9 = MmMapLockedPagesSpecifyCache(lVar9,0,1);
  }
  else {
    lVar9 = *(longlong *)(lVar9 + 0x18);
  }
  pbVar15 = (byte *)((ulonglong)*(uint *)(lVar19 + 0x10) + lVar9);
  pplVar3 = *(longlong ***)(*(longlong *)(param_1 + 0xd8) + 8);
  if (param_2 == &Ipv4Global) {
    uVar18 = (uint)(byte)((*pbVar15 & 0xf) << 2);
    *(uint *)(param_1 + 0x2c) = (uint)pbVar15[9];
    *(undefined2 *)(param_1 + 0x11a) = 9;
    if (*(char *)(param_1 + 0x130) == '\0') {
      uVar2 = *(ushort *)(pbVar15 + 6);
      if (((ushort)(uVar2 >> 8 | (uVar2 & 0xff1f) << 8) != 0) || ((uVar2 & 0x20) != 0)) {
        *(undefined4 *)(param_1 + 0x2c) = 0x2c;
      }
    }
    else {
      *(undefined4 *)(param_1 + 0x2c) = 0x2b;
    }
    lVar9 = 0xc;
  }
  else {
    *(uint *)(param_1 + 0x2c) = (uint)pbVar15[6];
    *(undefined2 *)(param_1 + 0x11a) = 6;
    lVar9 = 8;
  }
  psVar1 = (short *)(pbVar15 + lVar9);
  local_b8 = pplVar3;
  if (uVar18 != 0) {
    uVar13 = *(int *)(lVar19 + 0x10) + uVar18;
    if (uVar13 < *(uint *)(*(longlong *)(lVar19 + 8) + 0x28)) {
      *(int *)(lVar19 + 0x28) = *(int *)(lVar19 + 0x28) + uVar18;
      *(int *)(lVar19 + 0x18) = *(int *)(lVar19 + 0x18) - uVar18;
      *(uint *)(lVar19 + 0x10) = uVar13;
    }
    else {
      NdisAdvanceNetBufferDataStart(lVar19,uVar18,0,0);
    }
  }
  uVar13 = 0;
  *(byte *)(param_1 + 0x10) =
       *(byte *)(param_1 + 0x10) ^ (*(byte *)(param_1 + 0xb0) >> 4 ^ *(byte *)(param_1 + 0x10)) & 1;
  lVar19 = (*pplVar3)[5];
  iVar7 = (**(code **)(lVar19 + 0xa0))(psVar1);
  if (iVar7 != 0xe) {
    if (*(short *)(lVar19 + 0x1c) == 0x17) {
      if (((((*psVar1 != 0) || (psVar1[1] != 0)) || (psVar1[2] != 0)) ||
          ((psVar1[3] != 0 || (psVar1[4] != 0)))) ||
         ((psVar1[5] != 0 || ((psVar1[6] != 0 || (psVar1[7] != 0x100)))))) {
LAB_1c0046139:
        if (iVar7 < 2) {
          pplVar11 = pplVar3 + 1;
        }
        else if (iVar7 < 0xe) {
          pplVar11 = (longlong **)((longlong)pplVar3 + ((longlong)(iVar7 + -2) + 0xc4) * 4);
        }
        else {
          pplVar11 = (longlong **)*pplVar3;
        }
        uVar13 = *(uint *)pplVar11 & 0xfffffff;
      }
    }
    else if (*(byte *)psVar1 != 0x7f) goto LAB_1c0046139;
  }
  *(uint *)(param_1 + 0x14) = uVar13;
  *(short **)(param_1 + 0x18) = psVar1;
  uVar4 = *(undefined8 *)(param_1 + 0xd0);
  *(undefined8 *)(param_1 + 0x20) = uVar4;
  if (*(int *)(*(longlong *)(param_1 + 0xd0) + 0x18) == 1) {
    uVar14 = *(undefined4 *)(*(longlong *)(param_1 + 0xd0) + 0xa0);
  }
  else {
    uVar14 = 0;
  }
  *(undefined4 *)(param_1 + 0x28) = uVar14;
  *(uint *)(param_1 + 0x30) = uVar18;
  *(longlong ***)(param_1 + 0x38) = pplVar3;
  if ((*(byte *)(param_1 + 0xb0) & 0x10) == 0) {
    uVar14 = *(undefined4 *)(*(longlong *)(param_1 + 0xd8) + 0x18);
  }
  else {
    uVar14 = 0;
  }
  *(undefined4 *)(param_1 + 0x40) = uVar14;
  *(undefined8 *)(param_1 + 0x48) = 0;
  local_c8 = *(byte *)(param_1 + 0xb0) >> 3 & 1;
  local_c7 = *(byte *)(param_1 + 0x10) & 1;
  local_c4 = *(uint *)(local_b0 + 0x18);
  iVar7 = KeGetCurrentProcessorNumberEx(0);
  lVar19 = 0x58;
  lVar9 = 0x60;
  local_c0 = *(int **)((ulonglong)(uint)(iVar7 * 0x48) + gWfpPerProContext);
  iVar7 = *local_c0;
  if (iVar7 == 1) {
    local_88 = ZEXT816(0);
    local_78 = 0;
    KeQueryDpcWatchdogInformation(local_88);
    uVar10 = (ulonglong)(uint)local_88._4_4_;
    lVar12 = 0x40;
LAB_1c0045f34:
    *(ulonglong *)(lVar12 + (longlong)local_c0) = uVar10;
  }
  else {
    lVar12 = lVar19;
    if (iVar7 == 0) {
      *local_c0 = 3;
      memset(local_c0 + 2,0,0x60);
      local_c0[0x1a] = 1;
      uVar10 = _DAT_fffff78000000008;
      goto LAB_1c0045f34;
    }
    if (iVar7 == 2) {
      lVar12 = 0x30;
      uVar10 = _DAT_fffff78000000008;
      goto LAB_1c0045f34;
    }
    if (iVar7 == 3) {
      local_c0[0x1a] = local_c0[0x1a] + 1;
      uVar10 = _DAT_fffff78000000008;
      goto LAB_1c0045f34;
    }
  }
  if ((((gWfpPacketQueue & 4) == 0) ||
      (iVar7 = WfpIsNextHeaderIPsec(local_c4,param_1,lVar16), iVar7 == 0)) ||
     (((gWfpPacketQueue & 4) != 0 &&
      ((lVar12 = IpSecGetSecurityContext(lVar16), lVar12 != 0 &&
       (iVar7 = IPSecIsInboundContextRecvPacketBatched(lVar12), iVar7 != 0)))))) {
    if (((gWfpPacketQueue & 1) != 0) &&
       (iVar7 = WfpIsNextHeaderIPsec(local_c4,param_1,lVar16), iVar7 != 0)) {
      uVar17 = DAT_1c0206348;
      if ((local_c4 & 0xfffffffb) != 0) {
        uVar17 = DAT_1c0206358;
      }
      cVar6 = WfpIsInjectedByHandle(uVar17,lVar16);
      if (cVar6 == '\0') {
        local_e0 = CONCAT44(local_e0._4_4_,uVar18);
        local_f0 = lVar16;
        lVar12 = WfpQueueRcvPacket(local_c4,local_b8,uVar14);
        if (lVar12 == 0) {
          iVar7 = 3;
          goto LAB_1c0045f9f;
        }
      }
    }
LAB_1c0045f54:
    if ((local_c4 == 0) || (local_c4 == 4)) {
      local_f0 = CONCAT71(local_f0._1_7_,local_c8);
      local_f8 = CONCAT31(local_f8._1_3_,local_c7);
      local_e8 = uVar18;
      local_e0 = param_1;
      local_d8 = lVar16;
      iVar7 = ShimIpPacketInV4(psVar1,uVar4,local_b8,uVar14);
    }
    else if (local_c4 == 0x29) {
      local_f0 = CONCAT71(local_f0._1_7_,local_c8);
      local_f8 = CONCAT31(local_f8._1_3_,local_c7);
      local_e8 = uVar18;
      local_e0 = param_1;
      local_d8 = lVar16;
      iVar7 = ShimIpPacketInV6(psVar1,uVar4,local_b8,uVar14);
    }
    else {
      iVar7 = 1;
    }
    *(uint *)(lVar16 + 0x88) = *(uint *)(lVar16 + 0x88) & 0xff7fffff;
  }
  else {
    local_f8 = *(undefined4 *)(local_b8 + 1);
    lVar12 = IPsecAddRecvPacketToBatchingQueue
                       (lVar16,local_c4,uVar18,*(undefined4 *)(param_1 + 0x2c));
    if (lVar12 != 0) goto LAB_1c0045f54;
    iVar7 = 3;
  }
LAB_1c0045f9f:
  iVar8 = KeGetCurrentProcessorNumberEx(0);
  piVar5 = *(int **)((ulonglong)(uint)(iVar8 * 0x48) + gWfpPerProContext);
  iVar8 = *piVar5;
  if (iVar8 == 1) {
    local_70 = ZEXT816(0);
    local_60 = 0;
    KeQueryDpcWatchdogInformation(local_70);
    lVar9 = 0x48;
    lVar19 = 0x40;
    iVar8 = local_70._4_4_;
LAB_1c0046004:
    *(int *)(lVar9 + (longlong)piVar5) =
         (*(int *)(lVar9 + (longlong)piVar5) - *(int *)(lVar19 + (longlong)piVar5)) + iVar8;
  }
  else {
    if (iVar8 == 2) {
      lVar9 = 0x38;
      iVar8 = (int)_DAT_fffff78000000008;
      lVar19 = 0x30;
      goto LAB_1c0046004;
    }
    if (iVar8 == 3) {
      piVar5[0x1a] = piVar5[0x1a] + -1;
      iVar8 = (int)_DAT_fffff78000000008;
      if (piVar5[0x1a] == 0) {
        *piVar5 = 0;
      }
      goto LAB_1c0046004;
    }
  }
  if (iVar7 < 1) {
    if (*(longlong *)(lVar16 + 0x70) == 0xff) {
      iVar7 = *(int *)(lVar16 + 0x8c);
      if (iVar7 == -0x3fddfefc) {
        iVar7 = 9;
      }
      else if (iVar7 == 0x40000026) {
        iVar7 = 0x100;
      }
      else if (iVar7 == -0x3ffffdc1) {
        iVar7 = 4;
      }
      else if (iVar7 == -0x3fffffde) {
        iVar7 = 0xb;
      }
      else if (iVar7 == -0x3ffffdc2) {
        iVar7 = 3;
      }
      else {
        iVar7 = 0x11c;
      }
      *(int *)(param_1 + 0x128) = iVar7;
      if ((iVar7 == 3) && (*(undefined1 **)(*(longlong *)(param_1 + 0xc0) + 0x28) == &Ipv6Global)) {
        *(uint *)(param_1 + 300) =
             (*(ushort *)(param_1 + 0x11a) & 0xff00) << 8 |
             (uint)*(ushort *)(param_1 + 0x11a) << 0x18;
      }
      else {
        *(undefined4 *)(param_1 + 300) = 0;
      }
      *(undefined4 *)(lVar16 + 0x8c) = 0xc000023e;
      *(undefined8 *)(lVar16 + 0x70) = 0;
      lVar16 = local_98;
    }
    else {
      *(undefined4 *)(lVar16 + 0x8c) = 0x105;
      lVar16 = local_90;
    }
  }
  else {
    if (*(longlong *)(lVar16 + 0x70) == 0xff) {
      *(undefined8 *)(lVar16 + 0x70) = 0;
    }
    if (iVar7 == 1) {
      *(undefined4 *)(*(longlong *)(param_1 + 8) + 0x8c) = 0xc000021b;
    }
    else if (iVar7 == 2) {
      *(undefined4 *)(param_1 + 0x128) = 0xb;
      lVar16 = local_a8;
      goto LAB_1c0046039;
    }
    piVar5 = (int *)((ulonglong)*(uint *)(unaff_GS_OFFSET + 0x1a4) * 0xc0 + 0xb0 +
                    *(longlong *)(local_b0 + 0x4f60));
    *piVar5 = *piVar5 + 1;
    lVar16 = local_a0;
  }
LAB_1c0046039:
  **(longlong **)(lVar16 + 8) = param_1;
  *(longlong *)(lVar16 + 8) = param_1;
  __security_check_cookie(local_58 ^ (ulonglong)auStack_118);
  return;
}