clean up the following decompiled C code: 
/* WARNING: Function: _guard_dispatch_icall replaced with injection: guard_dispatch_icall */
/* PDB: Separated code (from the compiler): 1c00af90a - 1c00afbb1 for parent address: 1c0013510 */

void FUN_1c00af90a(undefined8 param_1,uint param_2)

{
  char *pcVar1;
  undefined uVar2;
  ulonglong uVar3;
  byte *pbVar4;
  int iVar5;
  longlong *plVar6;
  ulonglong uVar7;
  ushort uVar8;
  uint uVar9;
  int iVar10;
  uint uVar11;
  ulonglong uVar12;
  uint uVar13;
  uint *unaff_RBX;
  longlong unaff_RBP;
  longlong lVar14;
  byte bVar15;
  byte unaff_DIL;
  undefined2 *puVar16;
  ulonglong uVar17;
  undefined2 *puVar18;
  longlong unaff_R13;
  uint unaff_R14D;
  uint unaff_R15D;
  longlong **pplVar19;
  undefined4 extraout_XMM0_Da;
  undefined4 uVar20;
  undefined4 extraout_XMM0_Da_00;
  undefined8 in_stack_00000030;
  uint uStack0000000000000038;
  int iStack0000000000000040;
  undefined4 uStack0000000000000044;
  uint in_stack_00000048;
  byte *in_stack_00000050;
  longlong in_stack_00000058;
  undefined8 in_stack_00000060;
  undefined in_stack_00000068 [16];
  undefined8 in_stack_00000078;
  undefined8 in_stack_00000080;
  int iStack0000000000000088;
  undefined in_stack_00000098 [16];
  undefined in_stack_000000a8 [16];
  int in_stack_000000d0;
  longlong in_stack_00000130;
  ulonglong in_stack_00000150;
  ushort in_stack_000001d8;
  undefined2 in_stack_000001e0;
  byte in_stack_000001e8;
  byte in_stack_000001f0;
  uint in_stack_000001f8;
  
  if (3 < *(int *)(unaff_RBP + 0x6c)) {
    uVar11 = *(uint *)(unaff_RBP + 0xe4);
    if (uVar11 != 0) {
      if ((uint)(*(int *)(unaff_RBP + 0x198) - *(int *)(unaff_RBP + 0x278)) < uVar11) {
        iVar10 = uVar11 + (*(int *)(unaff_RBP + 0x278) - *(int *)(unaff_RBP + 0x198));
        *(int *)(unaff_RBP + 0xe4) = iVar10;
        if (iVar10 != 0) goto LAB_1c0013588;
      }
      else {
        *(uint *)(unaff_RBP + 0xe4) = unaff_R15D;
      }
    }
    *(uint *)(unaff_RBP + 0x2b4) = param_2 & 0xffffbfff;
  }
LAB_1c0013588:
  bVar15 = unaff_DIL | in_stack_000001f0;
  lVar14 = *(longlong *)(unaff_R13 + 8);
  uVar11 = (uint)bVar15;
  uStack0000000000000038 = (uint)bVar15;
  if ((*(byte *)(lVar14 + 10) & 5) == 0) {
    lVar14 = MmMapLockedPagesSpecifyCache(lVar14,0,1,0,unaff_R15D);
  }
  else {
    lVar14 = *(longlong *)(lVar14 + 0x18);
  }
  puVar18 = (undefined2 *)((ulonglong)*(uint *)(unaff_R13 + 0x10) + lVar14);
  *puVar18 = *(undefined2 *)(unaff_RBP + 0x70);
  puVar18[1] = *(undefined2 *)(unaff_RBP + 0x72);
  uVar9 = *unaff_RBX;
  *(uint *)(puVar18 + 2) =
       uVar9 >> 0x18 | (uVar9 & 0xff0000) >> 8 | (uVar9 & 0xff00) << 8 | uVar9 << 0x18;
  uVar9 = *(uint *)(unaff_RBP + 0x198);
  *(uint *)(puVar18 + 4) =
       uVar9 >> 0x18 | (uVar9 & 0xff0000) >> 8 | (uVar9 & 0xff00) << 8 | uVar9 << 0x18;
  *(byte *)((longlong)puVar18 + 0xd) = bVar15 & 0xfc;
  puVar18[7] = in_stack_000001d8 >> 8 | in_stack_000001d8 << 8;
  *(byte *)(puVar18 + 6) = (in_stack_000001e8 & 0xfc) << 2;
  puVar18[8] = in_stack_000001e0;
  if (((*(uint *)(unaff_RBP + 0x2b4) >> 0xd & 1) == 0) ||
     ((*(uint *)(unaff_RBP + 0x2b4) >> 0x11 & 1) != 0 ||
      (*(ushort *)(unaff_RBP + 0x78) >> 5 & 1) != 0)) {
    uVar9 = *(uint *)(unaff_R13 + 0x5c) & 0xfffffffc;
    *(uint *)(unaff_R13 + 0x5c) = uVar9;
  }
  else {
    if (((*(ushort *)(unaff_RBP + 0x78) & 1) != 0) ||
       (0 < (int)((*unaff_RBX - *(int *)(unaff_RBP + 0x84)) + unaff_R14D))) {
      uVar13 = *(uint *)(unaff_R13 + 0x5c) & 0xffffffde | 2;
      goto LAB_1c001366d;
    }
    uVar13 = *(uint *)(unaff_R13 + 0x5c);
    uVar9 = uVar13 & 0xfffffffc;
    *(uint *)(unaff_R13 + 0x5c) = uVar9;
    if (unaff_R14D == 0) {
      uVar13 = uVar13 & 0xffffffdc;
      goto LAB_1c001366d;
    }
  }
  uVar13 = unaff_R15D;
  if ((*(uint *)(unaff_RBP + 0x2b4) & 0x2000) != 0) {
    uVar13 = 0x20;
  }
  uVar13 = uVar9 & 0xffffffdf | uVar13;
LAB_1c001366d:
  *(uint *)(unaff_R13 + 0x5c) = uVar13;
  if ((bVar15 & 2) == 0) {
    if ((in_stack_000001e8 != 0x14) && ((*(byte *)(unaff_RBP + 0x2a9) & 4) != 0)) {
      uVar13 = in_stack_000001f8 + *(int *)(unaff_RBP + 0x270);
      *(undefined4 *)(puVar18 + 10) = 0xa080101;
      uVar9 = *(uint *)(unaff_RBP + 0x274);
      if (-1 < (int)(uVar13 - uVar9)) {
        *(uint *)(unaff_RBP + 0x274) = uVar13;
        uVar9 = uVar13;
      }
      *(uint *)(puVar18 + 0xc) =
           uVar9 >> 0x18 | (uVar9 & 0xff0000) >> 8 | (uVar9 & 0xff00) << 8 | uVar9 << 0x18;
      uVar9 = *(uint *)(unaff_RBP + 0x268);
      *(uint *)(puVar18 + 0xe) =
           uVar9 >> 0x18 | (uVar9 & 0xff0000) >> 8 | (uVar9 & 0xff00) << 8 | uVar9 << 0x18;
    }
  }
  else if (*unaff_RBX == *(uint *)(unaff_RBP + 0x7c)) {
    *unaff_RBX = *unaff_RBX + 1;
    *(byte *)((longlong)puVar18 + 0xd) = *(byte *)((longlong)puVar18 + 0xd) | 2;
    bVar15 = *(byte *)(unaff_RBP + 0x2a9);
    if ((bVar15 & 4) == 0) {
      in_stack_00000030._2_1_ = (char)unaff_R15D;
    }
    else {
      in_stack_00000030._2_1_ = '\x01';
    }
    if ((bVar15 & 1) != 0) {
      unaff_R15D = 1;
    }
    plVar6 = *(longlong **)(unaff_RBP + 0x18);
    puVar16 = puVar18 + 10;
    uVar2 = *(undefined *)(unaff_RBP + 0x2b1);
    _iStack0000000000000040 = *(ulonglong *)(unaff_RBP + 0x10);
    in_stack_00000030._4_4_ = *(uint *)(unaff_RBP + 0x268);
    if ((*(byte *)(unaff_RBP + 0x2ab) & 1) != 0) {
      if ((*(uint *)(unaff_RBP + 0x2b4) & 0x40) == 0) {
        in_stack_00000060 = *(undefined8 *)(_iStack0000000000000040 + 0x28);
        in_stack_00000080 = 0;
        in_stack_00000068 = ZEXT816(0);
        _iStack0000000000000088 = ZEXT816(0);
        in_stack_00000098 = ZEXT816(0);
        in_stack_000000a8 = ZEXT816(0);
        in_stack_00000078 = *(undefined8 *)(*plVar6 + 8);
        iVar10 = (**(code **)(*(longlong *)(_iStack0000000000000040 + 0x30) + 0xa8))
                           (&stack0x00000060,&stack0x00000088);
        if (iVar10 < 0) {
          iVar10 = 0x4d8;
          if (*(short *)(_iStack0000000000000040 + 0x18) != 0x17) {
            iVar10 = 0x22c;
          }
        }
        else {
          iVar10 = iStack0000000000000088;
        }
      }
      else {
        memset(&stack0x000000c0,0,0x88);
        iVar5 = InetQueryPathInfoAf(_iStack0000000000000040,plVar6,0,&stack0x000000c0,0);
        iVar10 = in_stack_000000d0;
        if ((iVar5 < 0) && (iVar10 = 0x4d8, *(short *)(_iStack0000000000000040 + 0x18) != 0x17)) {
          iVar10 = 0x22c;
        }
        if (in_stack_00000130 != 0) {
          (**(code **)(*(longlong *)(_iStack0000000000000040 + 0x30) + 0x80))();
        }
      }
      if (iVar10 + -0x14 != 0) {
        uVar8 = (ushort)(iVar10 + -0x14);
        puVar18[0xb] = uVar8 >> 8 | uVar8 << 8;
        *puVar16 = 0x402;
        puVar16 = puVar18 + 0xc;
      }
    }
    uVar9 = in_stack_000001f8;
    pbVar4 = in_stack_00000050;
    if ((bVar15 & 8) != 0) {
      *puVar16 = 0x301;
      *(undefined *)(puVar16 + 1) = 3;
      *(undefined *)((longlong)puVar16 + 3) = uVar2;
      puVar16 = puVar16 + 2;
    }
    if ((char)unaff_R15D != in_stack_00000030._2_1_) {
      *puVar16 = 0x101;
      puVar16 = puVar16 + 1;
    }
    if ((char)unaff_R15D != '\0') {
      *puVar16 = 0x204;
      puVar16 = puVar16 + 1;
    }
    if (in_stack_00000030._2_1_ != '\0') {
      *puVar16 = 0xa08;
      *(uint *)(puVar16 + 1) =
           in_stack_000001f8 >> 0x18 | (in_stack_000001f8 & 0xff0000) >> 8 |
           (in_stack_000001f8 & 0xff00) << 8 | in_stack_000001f8 << 0x18;
      *(uint *)(puVar16 + 3) =
           in_stack_00000030._4_4_ >> 0x18 | (in_stack_00000030._4_4_ & 0xff0000) >> 8 |
           (in_stack_00000030._4_4_ & 0xff00) << 8 | in_stack_00000030._4_4_ << 0x18;
      puVar16 = puVar16 + 5;
    }
    if (in_stack_00000050 != (byte *)0x0) {
      pcVar1 = (char *)((longlong)puVar16 + 1);
      *(undefined *)puVar16 = 0x22;
      *pcVar1 = '\x02';
      puVar16 = puVar16 + 1;
      if (*in_stack_00000050 != 0) {
        *pcVar1 = *in_stack_00000050 + 2;
        memcpy(puVar16,in_stack_00000050 + 1,*in_stack_00000050);
        puVar16 = (undefined2 *)((longlong)puVar16 + (ulonglong)*pbVar4);
      }
    }
    if (((ulonglong)puVar16 & 1) != 0) {
      *(undefined *)puVar16 = 1;
      puVar16 = (undefined2 *)((longlong)puVar16 + 1);
    }
    if (((ulonglong)puVar16 & 2) != 0) {
      *puVar16 = 0x101;
    }
    unaff_R15D = 0;
    uVar11 = uStack0000000000000038;
    if ((*(byte *)(unaff_RBP + 0x2a9) & 4) != 0) {
      *(uint *)(unaff_RBP + 0x274) = uVar9;
    }
  }
  if (((*(uint *)(unaff_RBP + 0x74) & 0x1000) == 0) ||
     ((int)(*(int *)(unaff_RBP + 0x88) - *unaff_RBX) < 1)) {
    puVar18[9] = (short)unaff_R15D;
  }
  else {
    *(byte *)((longlong)puVar18 + 0xd) = *(byte *)((longlong)puVar18 + 0xd) | 0x20;
    if (*(int *)(unaff_RBP + 0x88) - *unaff_RBX < 0x10000) {
      uVar8 = (short)*(int *)(unaff_RBP + 0x88) - (short)*unaff_RBX;
      puVar18[9] = uVar8 >> 8 | uVar8 * 0x100;
    }
    else {
      puVar18[9] = 0xffff;
    }
  }
  if (unaff_R14D == 0) {
    if (((uVar11 & 1) != 0) && (*(longlong *)(unaff_RBX + 2) == 0)) {
      uVar11 = *(uint *)(unaff_RBP + 0x94);
      if (uVar11 == 0) {
        uVar11 = *(uint *)(unaff_RBP + 0x74) >> 0x13 & 1;
      }
      if ((int)((*unaff_RBX - *(int *)(unaff_RBP + 0x7c)) - uVar11) < 0) {
        *(byte *)((longlong)puVar18 + 0xd) = *(byte *)((longlong)puVar18 + 0xd) | 1;
        *unaff_RBX = *unaff_RBX + 1;
        *(ushort *)(unaff_RBP + 0x78) = *(ushort *)(unaff_RBP + 0x78) | 4;
      }
    }
  }
  else {
    pplVar19 = *(longlong ***)(unaff_R13 + 0x20);
    _iStack0000000000000040 = CONCAT44(uStack0000000000000044,unaff_R14D);
    do {
      while( true ) {
        uVar3 = *(ulonglong *)(unaff_RBX + 4);
        lVar14 = *(longlong *)(unaff_RBX + 6);
        uVar9 = *(int *)(lVar14 + 0x28) - unaff_RBX[8];
        uVar11 = (uint)uVar3;
        if (unaff_R14D <= uVar3) {
          uVar11 = unaff_R14D;
        }
        if ((uVar11 < uVar9) && (uVar9 = (uint)uVar3, unaff_R14D <= uVar3)) {
          uVar9 = unaff_R14D;
        }
        lVar14 = (ulonglong)*(uint *)(lVar14 + 0x2c) + *(longlong *)(lVar14 + 0x20) +
                 (ulonglong)unaff_RBX[8];
        plVar6 = (longlong *)IoAllocateMdl(lVar14,uVar9,0,0,0);
        *pplVar19 = plVar6;
        if (plVar6 == (longlong *)0x0) {
          NetioExtendNetBuffer(extraout_XMM0_Da,iStack0000000000000040 - unaff_R14D);
          uVar20 = TcpUnsegmentTcbSend();
          *unaff_RBX = in_stack_00000048;
          TcpLocateTcbSend(uVar20,0);
          goto LAB_1c00137bc;
        }
        uVar20 = IoBuildPartialMdl(*(undefined8 *)(unaff_RBX + 6),plVar6,lVar14,uVar9);
        uVar3 = *(ulonglong *)(unaff_RBX + 4);
        pplVar19 = (longlong **)*pplVar19;
        uVar17 = (ulonglong)uVar9;
        uVar12 = (ulonglong)(*(int *)(*(undefined8 **)(unaff_RBX + 6) + 5) - unaff_RBX[8]);
        uVar7 = uVar3;
        if (uVar12 <= uVar3) {
          uVar7 = uVar12;
        }
        if (uVar17 < uVar7) {
          *unaff_RBX = *unaff_RBX + uVar9;
          unaff_RBX[8] = unaff_RBX[8] + uVar9;
          *(ulonglong *)(unaff_RBX + 4) = uVar3 - uVar17;
          goto LAB_1c0013784;
        }
        *(undefined8 *)(unaff_RBX + 6) = **(undefined8 **)(unaff_RBX + 6);
        if (uVar17 != uVar3) break;
        *(byte *)((longlong)puVar18 + 0xd) = *(byte *)((longlong)puVar18 + 0xd) | 8;
        lVar14 = **(longlong **)(unaff_RBX + 2);
        *(longlong *)(unaff_RBX + 2) = lVar14;
        if (lVar14 == 0) {
          if ((uStack0000000000000038 & 1) == 0) {
            *unaff_RBX = *unaff_RBX + uVar9;
          }
          else {
            uVar11 = *(uint *)(unaff_RBP + 0x94);
            if (uVar11 == 0) {
              uVar11 = *(uint *)(unaff_RBP + 0x74) >> 0x13 & 1;
            }
            if ((int)((*unaff_RBX - *(int *)(unaff_RBP + 0x7c)) - uVar11) < 0) {
              *(byte *)((longlong)puVar18 + 0xd) = *(byte *)((longlong)puVar18 + 0xd) | 1;
              *unaff_RBX = *unaff_RBX + uVar9 + 1;
              *(ushort *)(unaff_RBP + 0x78) = *(ushort *)(unaff_RBP + 0x78) | 4;
            }
            else {
              *unaff_RBX = *unaff_RBX + uVar9;
            }
          }
          goto LAB_1c0013784;
        }
        *unaff_RBX = *unaff_RBX + uVar9;
        *(undefined8 *)(unaff_RBX + 4) = *(undefined8 *)(lVar14 + 0x18);
        *(undefined8 *)(unaff_RBX + 6) = *(undefined8 *)(lVar14 + 8);
        unaff_RBX[8] = *(uint *)(lVar14 + 0x10);
        LOCK();
        *(int *)(lVar14 + 0x3c) = *(int *)(lVar14 + 0x3c) + 1;
        UNLOCK();
        *(int *)(in_stack_00000058 + 0x10) = *(int *)(in_stack_00000058 + 0x10) + 1;
        unaff_R14D = unaff_R14D - uVar9;
        if (unaff_R14D == 0) goto LAB_1c0013784;
      }
      *unaff_RBX = *unaff_RBX + uVar9;
      *(ulonglong *)(unaff_RBX + 4) = uVar3 - uVar17;
      unaff_RBX[8] = 0;
      unaff_R14D = unaff_R14D - uVar9;
    } while (unaff_R14D != 0);
LAB_1c0013784:
    *pplVar19 = (longlong *)0x0;
    NetioExtendNetBuffer(uVar20,_iStack0000000000000040 & 0xffffffff);
    if ((*(byte *)(*(longlong *)(unaff_RBP + 0x18) + 0x29) & 1) != 0) {
      in_stack_00000030._4_4_ = 0x40;
      plVar6 = (longlong *)NetioAllocateMdl((longlong)&stack0x00000030 + 4);
      *pplVar19 = plVar6;
      if (plVar6 != (longlong *)0x0) {
        *plVar6 = 0;
        NetioExtendNetBuffer(extraout_XMM0_Da_00,in_stack_00000030._4_4_);
        *(int *)(unaff_R13 + 0x18) = *(int *)(unaff_R13 + 0x18) - in_stack_00000030._4_4_;
        *(int *)(unaff_R13 + 0x58) = *(int *)(unaff_R13 + 0x58) + in_stack_00000030._4_4_;
        *(uint *)(unaff_R13 + 0x5c) = *(uint *)(unaff_R13 + 0x5c) | 4;
      }
    }
    if ((*(ushort *)(unaff_RBP + 0x298) != 0) && ((*(ushort *)(unaff_RBP + 0x298) & 1) != 0)) {
      FUN_1c00afb65();
      return;
    }
  }
LAB_1c00137bc:
  __security_check_cookie(in_stack_00000150 ^ (ulonglong)&stack0x00000000);
  return;
}