IopInitializeActiveConnectBlock

VOID __fastcall IopInitializeActiveConnectBlock(INT64 a1, INT64 *a2){
  unsigned int v4; 
  __int64 v5; 
  __int64 v6; 
  INT64 v7; 
  INT64 **v8; 
  INT64 **v9; 
  memset((INT64)a2, 0i64);
  if( !*(_DWORD *)(a1 + 8) )
  {
    a2[1] = (INT64)a2;
    *a2 = (INT64)a2;
    KeInitializeEvent((_KEVENT *)(a2 + 5), SynchronizationEvent, 1u);
    *((_DWORD *)a2 + 16) = 1;
    v4 = *(_DWORD *)(a1 + 64);
    *((_DWORD *)a2 + 4) = v4;
    IopAcquireReleaseConnectLockInternal(0i64, 1, 2);
    v5 = ActiveConnectList;
    v6 = 0i64;
    while( (__int64 *)v5 != &ActiveConnectList )
    {
      if( *(_DWORD *)(v5 + 16) == v4 )
      {
        v6 = v5;
        break;
      }
      if( *(_DWORD *)(v5 + 16) > v4 )
        break;
      v5 = *(_QWORD *)v5;
    }
    if( v6 )
    {
      a2[3] = *(_QWORD *)(v6 + 24);
      a2[4] = *(_QWORD *)(v6 + 32);
      _InterlockedIncrement(*(volatile signed __int32 **)(v6 + 32));
    }
    else
    {
      a2[3] = (INT64)(a2 + 5);
      a2[4] = (INT64)(a2 + 8);
    }
    v7 = ActiveConnectList;
    if( (__int64 *)ActiveConnectList != &ActiveConnectList )
    {
      while( *(_DWORD *)(v7 + 16) <= *((_DWORD *)a2 + 4) )
      {
        v7 = *(_QWORD *)v7;
        if( (__int64 *)v7 == &ActiveConnectList )
          goto LABEL_21;
      }
      v9 = *(INT64 ***)(v7 + 8);
      if( *v9 != (INT64 *)v7 )
        goto LABEL_23;
      *a2 = v7;
      a2[1] = (INT64)v9;
      *v9 = a2;
      *(_QWORD *)(v7 + 8) = a2;
LABEL_21:
      if( (__int64 *)v7 != &ActiveConnectList )
        goto LABEL_9;
    }
    v8 = (INT64 **)qword_140C452C8;
    if( *(__int64 **)qword_140C452C8 == &ActiveConnectList )
    {
      *a2 = (INT64)&ActiveConnectList;
      a2[1] = (INT64)v8;
      *v8 = a2;
      qword_140C452C8 = (__int64)a2;
LABEL_9:
      IopAcquireReleaseConnectLockInternal(0i64, 0, 2);
      return;
    }
LABEL_23:
    __fastfail(3u);
  }
}

Referenced by:

IoDisconnectInterrupt
IopConnectInterrupt