clean up the following decompiled C code: 
longlong WfpAlepSetSecurity(longlong param_1,uint *param_2,ulonglong param_3)

{
  uint *puVar1;
  uint *puVar2;
  longlong lVar3;
  int iVar4;
  int iVar5;
  int iVar6;
  char cVar7;
  longlong lVar8;
  uint uVar9;
  int *piVar10;
  undefined8 uVar11;
  uint uVar12;
  char in_CR8;
  undefined4 uVar13;
  int extraout_XMM0_Da;
  int extraout_XMM0_Da_00;
  int iVar14;
  int *local_res10 [2];
  int *local_res20;
  longlong local_88;
  longlong local_80;
  longlong local_78;
  undefined8 local_70;
  uint *local_68;
  uint *local_60;
  longlong local_58;
  undefined local_50 [16];
  undefined8 local_40;
  
  local_res20 = (int *)0x0;
  local_res10[0] = (int *)0x0;
  local_70 = 0;
  local_58 = 0;
  local_88 = 0;
  uVar12 = 1;
  local_80 = 0;
  local_78 = 0;
  local_50 = ZEXT816(0);
  local_40 = 0;
  if (*param_2 < 3) {
    if (param_2[1] < 3) {
      lVar8 = WfpPoolAllocNonPaged(param_3,0x73536c41,local_res10);
      piVar10 = local_res10[0];
      if (lVar8 == 0) {
        memcpy(local_res10[0],param_2,param_3);
        uVar13 = KeAcquireInStackQueuedSpinLock(param_1,local_50);
        do {
        } while (*(int *)(param_1 + 8) != 0);
        if (*(longlong *)(param_1 + 0x80) == 0) {
          if ((*(uint *)(param_1 + 0x20) & 0x10) != 0) {
            uVar11 = 0xc0000429;
            goto LAB_1c00a9f45;
          }
          if ((*(uint *)(param_1 + 0x20) & 0x20) != 0) {
            uVar11 = 0xc000023b;
            goto LAB_1c00a9f45;
          }
          lVar8 = WfpAleAllocateSecureSocketPolicy(&local_res20);
          piVar10 = local_res10[0];
          if (lVar8 == 0) {
            LOCK();
            *local_res20 = *local_res20 + 1;
            UNLOCK();
            if (*local_res10[0] - 1U < 2) {
              if (param_3 < 0x54) {
LAB_1c00a9f5a:
                uVar11 = 0x80000005;
                iVar14 = extraout_XMM0_Da;
              }
              else {
                puVar1 = (uint *)(local_res10[0] + 0x12);
                if (0x402 < *puVar1) goto LAB_1c00a9f5a;
                local_60 = (uint *)(local_res10[0] + 0x13);
                if (0x402 < *local_60) goto LAB_1c00a9f5a;
                local_68 = (uint *)(local_res10[0] + 0x14);
                if ((0xfffa < *local_68) || (param_3 < *local_68 + 0x54 + *local_60 + *puVar1))
                goto LAB_1c00a9f5a;
                if ((*(longlong *)(local_res10[0] + 0x10) == 0) ||
                   (cVar7 = ExGetPreviousMode(), iVar14 = extraout_XMM0_Da_00, cVar7 == '\0')) {
                  iVar14 = piVar10[4];
                  iVar4 = piVar10[5];
                  iVar5 = piVar10[6];
                  local_res20[0xb] = piVar10[3];
                  local_res20[0xc] = iVar14;
                  local_res20[0xd] = iVar4;
                  local_res20[0xe] = iVar5;
                  iVar14 = piVar10[7];
                  iVar4 = piVar10[8];
                  iVar5 = piVar10[9];
                  iVar6 = piVar10[10];
                  local_res20[0xf] = iVar14;
                  local_res20[0x10] = iVar4;
                  local_res20[0x11] = iVar5;
                  local_res20[0x12] = iVar6;
                  iVar4 = piVar10[0xc];
                  iVar5 = piVar10[0xd];
                  iVar6 = piVar10[0xe];
                  local_res20[0x13] = piVar10[0xb];
                  local_res20[0x14] = iVar4;
                  local_res20[0x15] = iVar5;
                  local_res20[0x16] = iVar6;
                  lVar3 = *(longlong *)(piVar10 + 0x10);
                  *(longlong *)(local_res20 + 0x1e) = lVar3;
                  if (lVar3 != 0) {
                    *(undefined8 *)(local_res20 + 0x1e) = 0;
                    local_58 = lVar3;
                  }
                  puVar2 = (uint *)(piVar10 + 2);
                  uVar9 = *puVar2;
                  uVar12 = ~uVar9 & 1;
                  if ((uVar9 & 2) != 0) {
                    LOCK();
                    *(uint *)(param_1 + 0x24) = *(uint *)(param_1 + 0x24) | 1;
                    UNLOCK();
                    uVar9 = *puVar2;
                    piVar10 = local_res10[0];
                  }
                  if ((uVar9 & 8) != 0) {
                    LOCK();
                    *(uint *)(param_1 + 0x24) = *(uint *)(param_1 + 0x24) | 2;
                    UNLOCK();
                    uVar9 = *puVar2;
                    piVar10 = local_res10[0];
                  }
                  if ((uVar9 & 4) != 0) {
                    if ((piVar10[1] & 1U) == 0) goto LAB_1c00a9f62;
                    LOCK();
                    *(uint *)(param_1 + 0xa8) = *(uint *)(param_1 + 0xa8) | 0x10;
                    UNLOCK();
                    piVar10 = local_res10[0];
                  }
                  if ((*puVar1 != 0) &&
                     ((lVar8 = WfpAleExtractExplicitCredentials
                                         (piVar10 + 0x15,*puVar1,*local_60,*local_68,&local_88,
                                          &local_80,&local_78), lVar8 != 0 ||
                      (lVar8 = WfpAleInsertCredentialInformation
                                         (local_88,*puVar1,local_80,*local_60,local_78,*local_68,
                                          local_res20 + 0x1c), lVar8 != 0)))) goto LAB_1c0003ce2;
                  goto LAB_1c0003cc7;
                }
LAB_1c00a9f62:
                uVar11 = 0xc000000d;
              }
              lVar8 = WfpReportSysErrorAsNtStatus(iVar14,"WfpAlepSetSecurity",uVar11);
            }
            else {
LAB_1c0003cc7:
              local_res20[0x20] = piVar10[1];
              local_res20[2] = *piVar10;
              if (uVar12 != 0) {
                LOCK();
                *(uint *)(param_1 + 0x20) = *(uint *)(param_1 + 0x20) | 0x4000;
                UNLOCK();
                piVar10 = local_res10[0];
              }
            }
          }
        }
        else {
          uVar11 = 0xc00000ef;
LAB_1c00a9f45:
          lVar8 = WfpReportSysErrorAsNtStatus(uVar13,"WfpAlepSetSecurity",uVar11);
          piVar10 = local_res10[0];
        }
LAB_1c0003ce2:
        KeReleaseInStackQueuedSpinLock(local_50);
        if (lVar8 == 0) {
          if ((local_58 == 0) || (in_CR8 != '\0')) {
LAB_1c0003d36:
            KeAcquireInStackQueuedSpinLock(param_1,local_50);
            do {
            } while (*(int *)(param_1 + 8) != 0);
            if (*(longlong *)(param_1 + 0x80) == 0) {
              *(int **)(param_1 + 0x80) = local_res20;
            }
            else {
              lVar8 = -0x3fffff11;
            }
            KeReleaseInStackQueuedSpinLock(local_50);
            piVar10 = local_res10[0];
          }
          else {
            lVar8 = WfpAleCreateTokenFromLogonId(local_58,&local_70);
            if (lVar8 == 0) {
              lVar8 = WfpAleSetLogonIdMappedLocalTokenInformation(param_1,local_70);
              local_70 = 0;
              if (lVar8 == 0) goto LAB_1c0003d36;
            }
          }
        }
      }
      if (piVar10 != (int *)0x0) {
        WfpPoolFree(local_res10);
      }
      goto LAB_1c0003d8c;
    }
    uVar11 = 0xc000000d;
  }
  else {
    uVar11 = 0xc00000f0;
  }
  lVar8 = WfpReportSysErrorAsNtStatus(0,"WfpAlepSetSecurity",uVar11);
LAB_1c0003d8c:
  if ((lVar8 != 0) && (local_res20 != (int *)0x0)) {
    WfpAleDereferenceSecureSocketPolicy();
  }
  if (local_88 != 0) {
    WfpPoolFree(&local_88);
  }
  if (local_80 != 0) {
    WfpPoolFree(&local_80);
  }
  if (local_78 != 0) {
    WfpPoolFree(&local_78);
  }
  if (lVar8 != 0) {
    WfpReportError(lVar8,"WfpAlepSetSecurity");
  }
  return lVar8;
}