IopAllocateBackpocketIrp

_IRP *__stdcall IopAllocateBackpocketIrp(_DEVICE_OBJECT *DeviceObject, INT8 StackSize, UINT8 ReadRequest){
  int v3; 
  _ETHREAD *CurrentThread; 
  _IRP *result; 
  _IRP *v7; 
  _LARGE_INTEGER v8; 
  VOID *retaddr; 
  _LARGE_INTEGER v10; 

  v3 = StackSize;
  if( StackSize > *(&stru_140C452E0 + 1984) )
    return 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  if( !ReadRequest )
  {
    if( (_ETHREAD *)*(&stru_140C452E0 + 243) != CurrentThread )
    {
      v8.QuadPart = -300000000i64;
      while( _InterlockedExchange((_DWORD *)&stru_140C452E0 + 484, 1) == 1 )
      {
        if( KeWaitForSingleObject((UINT64)&stru_140C452E0 + 1952, 0, 0, 0, (INT64)&v8) == 258 )
        {
          result = IopAllocateIrpExReturn(DeviceObject, v3, 0, retaddr);
          if( result )
            return result;
        }
      }
      v7 = (_IRP *)*(&stru_140C452E0 + 241);
      IoInitializeIrp(*(&stru_140C452E0 + 241), 72 * v3 + 280, v3 + 1);
      v7->AllocationFlags = 33;
      *(&stru_140C452E0 + 243) = KeGetCurrentThread();
      goto LABEL_9;
    }
    v7 = (_IRP *)*(&stru_140C452E0 + 247);
    if( *(&stru_140C452E0 + 247) )
    {
LABEL_19:
      *(&stru_140C452E0 + 247) = **(&stru_140C452E0 + 247);
      IoInitializeIrp(v7, 72 * StackSize + 280, StackSize + 1);
      v7->Tail.IrpExtension = --v7->Tail.CurrentStackLocation;
      v7->AllocationFlags = 33;
      goto LABEL_20;
    }
    return 0i64;
  }
  if( (_ETHREAD *)*(&stru_140C452E0 + 237) == CurrentThread )
  {
    v7 = (_IRP *)*(&stru_140C452E0 + 247);
    if( !*(&stru_140C452E0 + 247) )
      KeBugCheckEx(0x11Eu, 0i64, 0i64, 0i64, 0i64);
    goto LABEL_19;
  }
  v10.QuadPart = -300000000i64;
  while( _InterlockedExchange((_DWORD *)&stru_140C452E0 + 472, 1) == 1 )
  {
    if( KeWaitForSingleObject((UINT64)&stru_140C452E0 + 1904, 0, 0, 0, (INT64)&v10) == 258 )
    {
      result = IopAllocateIrpExReturn(DeviceObject, v3, 0, retaddr);
      if( result )
        return result;
    }
  }
  v7 = (_IRP *)*(&stru_140C452E0 + 235);
  IoInitializeIrp(*(&stru_140C452E0 + 235), 72 * v3 + 280, v3 + 1);
  v7->AllocationFlags = 33;
  *(&stru_140C452E0 + 237) = KeGetCurrentThread();
LABEL_9:
  v7->Tail.IrpExtension = --v7->Tail.CurrentStackLocation;
LABEL_20:
  --v7->StackCount;
  --v7->CurrentLocation;
  if( IopIsActivityTracingEnabled() )
    IopInitActivityIdIrp(v7);
  return v7;
}

Referenced by:

IoAsynchronousPageWrite
IoSynchronousPageWriteEx