PfpFileBuildReadSupport

__int64 __fastcall PfpFileBuildReadSupport(_QWORD *a1, _DWORD *a2, unsigned int a3, char a4, __int64 a5){
  void *v5; 
  __int64 v8; 
  __int64 v10; 
  __int64 v11; 
  int v12; 
  int v13; 
  __int64 v14; 
  __m128i *v15; 
  int v16; 
  UINT64 v17; 
  __m128i v18; 
  unsigned __int64 v19; 
  NTSTATUS Section; 
  __int64 v21; 
  VOID *v22; 
  __int128 v23; 
  __int64 v24; 
  __m128i v26; 
  __m128i v27; 
  INT64 SectionPageProtection; 
  INT64 AllocationAttributes; 
  void *v30; 
  __int128 v31; 
  __m256i FileHandle; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  int v34; 
  VOID *SectionHandle; 
  unsigned int v36; 

  v36 = 0;
  memset(&FileHandle, 0, 24);
  v5 = 0i64;
  SectionHandle = 0i64;
  v8 = *a1;
  FileHandle.m256i_i64[3] = 0x200000000i64;
  v10 = a3;
  v11 = a1[1];
  v30 = 0i64;
  v12 = a4 != 0 ? 32 : 129;
  memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
  v13 = a4 != 0 ? 285212672 : 0x4000000;
  v34 = v13;
  v31 = 0i64;
  v14 = (unsigned __int128)(((__int64)a2 - *(unsigned int *)(v8 + 40) - v8) * (__int128)0x2AAAAAAAAAAAAAABi64) >> 64;
  v15 = (__m128i *)(v11 + 32 * (((unsigned __int64)v14 >> 63) + (v14 >> 3)));
  if( v11 && (v15[1].m128i_i64[1] & 0x400000000i64) != 0 )
  {
    v26 = v15[1];
    v18 = *v15;
    FileHandle.m256i_i64[2] = v15[1].m128i_i64[0];
    v19 = _mm_srli_si128(v26, 8).m128i_u64[0] | 0x1000000000i64;
    *(__m128i *)FileHandle.m256i_i8 = v18;
    v17 = v18.m128i_i64[0];
    FileHandle.m256i_i64[3] = v19;
  }
  else
  {
    PfpFileSetupObjectAttributes((__int64)a1, (__int64)a2, v10, (__int64)&v31, (__int64)&ObjectAttributes, &v36);
    v16 = PfpOpenHandleCreate(
            (__int64)&FileHandle,
            a1[5],
            (__int64)ObjectAttributes.ObjectName,
            (__int64)ObjectAttributes.RootDirectory,
            v12,
            v36,
            0x80u,
            a1[2] + (v10 << 6));
    if( v16 < 0 )
    {
      v19 = FileHandle.m256i_u64[3];
      goto LABEL_11;
    }
    v17 = FileHandle.m256i_i64[0];
    v16 = PfpFileCheckAttributesForPrefetch((VOID *)FileHandle.m256i_i64[0]);
    if( v16 < 0 )
    {
      v19 = FileHandle.m256i_u64[3];
      goto LABEL_20;
    }
    v18 = *(__m128i *)FileHandle.m256i_i8;
    v13 = v34;
    if( a1[1] )
    {
      v27 = *(__m128i *)&FileHandle.m256i_u64[2];
      *v15 = *(__m128i *)FileHandle.m256i_i8;
      v15[1] = v27;
      v19 = _mm_srli_si128(v27, 8).m128i_u64[0] | 0x1000000000i64;
      FileHandle.m256i_i64[3] = v19;
    }
    else
    {
      v19 = FileHandle.m256i_u64[3];
    }
  }
  if( (*a2 & 1) != 0 && !a4 && *(_QWORD *)(*(_QWORD *)(_mm_srli_si128(v18, 8).m128i_u64[0] + 40) + 16i64) )
  {
    v16 = -1073741791;
    goto LABEL_11;
  }
  ObjectAttributes.RootDirectory = 0i64;
  ObjectAttributes.ObjectName = 0i64;
  LODWORD(AllocationAttributes) = v13;
  ObjectAttributes.Length = 48;
  ObjectAttributes.Attributes = 576;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  LODWORD(SectionPageProtection) = 2;
  Section = NtCreateSection(
              (UINT64)&SectionHandle,
              5ui64,
              (INT64)&ObjectAttributes,
              0i64,
              SectionPageProtection,
              AllocationAttributes,
              v17);
  v16 = Section;
  if( Section >= 0 )
  {
    v16 = PfpFileBuildReadList((__int64)a1, (__int64)a2, a4, &v30);
    if( v16 < 0 )
    {
      v5 = v30;
    }
    else
    {
      v21 = a5;
      v22 = SectionHandle;
      v19 = 0x200000000i64;
      v23 = *(_OWORD *)&FileHandle.m256i_u64[2];
      FileHandle.m256i_i64[0] = 0i64;
      SectionHandle = 0i64;
      *(_QWORD *)(a5 + 40) = v22;
      v16 = 0;
      v24 = (__int64)v30;
      *(__m128i *)(v21 + 8) = v18;
      *(_QWORD *)v21 = v24;
      *(_OWORD *)(v21 + 24) = v23;
      FileHandle.m256i_i64[3] = 0x200000000i64;
      *(_OWORD *)&FileHandle.m256i_u64[1] = 0i64;
      *(_QWORD *)(v21 + 48) = a2;
    }
    goto LABEL_11;
  }
  if( a4 && Section == -1073740749 )
  {
LABEL_11:
    if( (v19 & 0x100000000i64) == 0 )
      goto LABEL_12;
  }
LABEL_20:
  if( (*a2 & 8) == 0 )
  {
    *a2 |= 8u;
    ++*(_DWORD *)(*a1 + 124i64);
  }
LABEL_12:
  if( SectionHandle )
    NtClose((UINT64)SectionHandle);
  if( (v19 & 0x400000000i64) != 0 )
    PfpOpenHandleClose(&FileHandle, a1[5]);
  if( v5 )
    ExFreePoolWithTag(v5, 0);
  return(unsigned int)v16;
}

Referenced by:

PfpPrefetchFiles
PfpPrefetchFilesTrickle