IopDestroyActiveConnectBlock

VOID __fastcall IopDestroyActiveConnectBlock(volatile INT32 *a1){
  __int64 v2; 
  volatile signed __int32 *v3; 
  struct _KEVENT *v4; 
  char v5; 
  signed __int32 v6; 
  __int64 v7; 
  volatile INT32 **v8; 
  _ETHREAD *CurrentThread; 
  struct _KEVENT Event; 
  memset(&Event, 0, sizeof(Event));
  if( *((_QWORD *)a1 + 3) )
  {
    v2 = *((_QWORD *)a1 + 4);
    v3 = a1 + 16;
    KeInitializeEvent(&Event, SynchronizationEvent, 0);
    v4 = 0i64;
    v5 = 0;
    IopAcquireReleaseConnectLockInternal(0i64, 1, 2);
    v6 = _InterlockedDecrement((volatile signed __int32 *)v2);
    if( (volatile signed __int32 *)v2 == v3 )
    {
      if( v6 )
      {
        v5 = 1;
        *((_QWORD *)a1 + 9) = &Event;
      }
    }
    else
    {
      if( !v6 )
        v4 = *(struct _KEVENT **)(v2 + 8);
      _InterlockedAdd(v3, 0xFFFFFFFF);
    }
    v7 = *(_QWORD *)a1;
    if( *(volatile INT32 **)(*(_QWORD *)a1 + 8i64) != a1 || (v8 = (volatile INT32 **)*((_QWORD *)a1 + 1), *v8 != a1) )
      __fastfail(3u);
    *v8 = (volatile INT32 *)v7;
    *(_QWORD *)(v7 + 8) = v8;
    IopAcquireReleaseConnectLockInternal(0i64, 0, 2);
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)CurrentThread + 242);
    if( v5 )
    {
      KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
    }
    else if( v4 )
    {
      KeSetEvent(v4, 0);
    }
    KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
  }
}

Referenced by:

IoDisconnectInterrupt
IopConnectInterrupt