HalpBuildScatterGatherListThin

NTSTATUS __stdcall HalpBuildScatterGatherListThin(
        INT64 a1,
        INT64 a2,
        INT64 a3,
        INT64 a4,
        INT64 a5,
        INT64 a6,
        INT8 a7,
        INT64 a8,
        INT64 a9,
        INT64 a10,
        PVOID P,
        INT64 a12,
        INT64 a13){
  char v13; 
  INT64 v14; 
  INT64 v16; 
  int v17; 
  unsigned __int64 v19; 
  unsigned int v20; 
  unsigned int v21; 
  int v22; 
  INT64 i; 
  int v24; 
  unsigned int v25; 
  unsigned int v26; 
  __int64 v27; 
  __int64 v28; 
  UINT64 v29; 
  void *PoolWithTag; 
  INT64 v31; 
  __int64 v32; 

  v13 = 0;
  v14 = a4;
  v16 = a2;
  if( !a4 )
    return -1073741811;
  if( a13 )
    *(_QWORD *)a13 = 0i64;
  do
  {
    v19 = *(unsigned int *)(v14 + 40);
    if( a5 < v19 )
      break;
    v14 = *(_QWORD *)v14;
    a5 -= v19;
  }
  while( v14 );
  if( !v14 )
    return -1073741811;
  v20 = 0;
  v21 = a6;
  v22 = a5;
  for( i = v14; v21; v21 -= v25 )
  {
    if( !i )
      break;
    v24 = *(_DWORD *)(i + 40);
    v25 = v21;
    i = *(_QWORD *)i;
    v26 = v24 - v22;
    if( v26 <= v21 )
      v25 = v26;
    ++v20;
    v22 = 0;
  }
  v27 = 0i64;
  if( !v21 )
    v27 = v20;
  if( !(_DWORD)v27 )
    return -1073741811;
  v28 = 3 * v27;
  v29 = 24 * v27 + 120;
  if( P )
  {
    if( (unsigned int)a12 < v29 )
      return -1073741789;
    PoolWithTag = P;
  }
  else
  {
    PoolWithTag = ExAllocatePoolWithTag(0x200ui64, v29, 543973704i64);
    if( !PoolWithTag )
      return -1073741670;
    v16 = a2;
  }
  v31 = (INT64)PoolWithTag + 8 * v28 + 16;
  *(_BYTE *)(v31 + 97) = P == 0i64;
  *(_QWORD *)(v31 + 24) = a1;
  *(_QWORD *)(v31 + 32) = v16;
  v32 = *(_QWORD *)(v16 + 32);
  *(_QWORD *)(v31 + 88) = 0i64;
  *(_QWORD *)(v31 + 40) = v32;
  *(_QWORD *)(v31 + 64) = a8;
  *(_QWORD *)(v31 + 72) = a9;
  *(_DWORD *)(v31 + 56) = a6;
  *(_QWORD *)(v31 + 48) = v14;
  *(_DWORD *)(v31 + 60) = a5;
  *(_QWORD *)(v31 + 80) = PoolWithTag;
  *(_BYTE *)(v31 + 96) = a7 & 1;
  *(_DWORD *)(v31 + 16) = 1;
  *(_BYTE *)(v31 + 98) = 0;
  if( a3 )
  {
    *(_QWORD *)(a3 + 88) = v31;
    *(_QWORD *)(v31 + 88) = a3 + 8;
    _m_prefetchw((const void *)(a3 + 8));
    v13 = _InterlockedOr((volatile signed __int32 *)(a3 + 8), 4u);
  }
  if( (v13 & 2) != 0 )
  {
    v17 = -1073741536;
    goto LABEL_27;
  }
  v17 = HalpConstructScatterGatherListThin(v31);
  if( v17 < 0 )
  {
LABEL_27:
    if( *(_BYTE *)(v31 + 97) )
      ExFreePoolWithTag(PoolWithTag, 0);
    return v17;
  }
  if( a13 )
    *(_QWORD *)a13 = PoolWithTag;
  return v17;
}

Referenced by:

HalBuildScatterGatherListThin
HalBuildScatterGatherListThinEx
HalGetScatterGatherListThin
HalGetScatterGatherListThinEx