sub_140963044

__int64 __fastcall sub_140963044(__int64 a1, __int64 a2, __int64 a3, __int64 a4){
  __int64 v4; 
  unsigned int v7; 
  unsigned int *v8; 
  unsigned int *v9; 
  unsigned int i; 
  __int64 v11; 
  unsigned int *v12; 
  unsigned int v13; 
  unsigned int *v14; 
  unsigned int *v15; 
  unsigned int j; 
  __int64 v17; 
  unsigned int *v18; 
  unsigned int v19; 
  unsigned int *v20; 
  int v21; 
  int v22; 
  unsigned int v23; 
  VOID **PoolWithTag; 
  int v25; 
  unsigned int v26; 
  __int64 v27; 
  unsigned int v28; 
  int v29; 
  unsigned int v30; 
  unsigned int v31; 
  unsigned __int64 k; 
  unsigned int v33; 

  v4 = 0i64;
  if( !a2 || !a4 )
    return(unsigned int)-1073741811;
  v8 = *(unsigned int **)(a1 + 8);
  if( v8 && *(_DWORD *)a1 > 3u )
  {
    v9 = *(unsigned int **)(a1 + 8);
    for( i = 0; i < 3; ++i )
    {
      v11 = *v9;
      v12 = v9 + 1;
      if( v9 + 1 < v9 )
        goto LABEL_17;
      v9 = (unsigned int *)((char *)v12 + v11);
      if( (unsigned int *)((char *)v12 + v11) < v12 )
        goto LABEL_17;
    }
    v13 = *v9;
    v14 = v9 + 1;
    if( v9 + 1 < v9 )
    {
LABEL_17:
      v7 = -1073741675;
    }
    else
    {
      v15 = 0i64;
      if( v13 )
        v15 = v14;
      v7 = 0;
      if( v13 != 8 )
        return(unsigned int)-1073741789;
      v4 = *(_QWORD *)v15;
    }
  }
  else
  {
    v7 = -1073741811;
  }
  if( (v7 & 0x80000000) != 0 )
    return v7;
  if( !v8 || *(_DWORD *)a1 <= 4u )
    return(unsigned int)-1073741811;
  for( j = 0; j < 4; ++j )
  {
    v17 = *v8;
    v18 = v8 + 1;
    if( v8 + 1 < v8 )
      return(unsigned int)-1073741675;
    v8 = (unsigned int *)((char *)v18 + v17);
    if( (unsigned int *)((char *)v18 + v17) < v18 )
      return(unsigned int)-1073741675;
  }
  v19 = *v8;
  if( v8 + 1 < v8 )
    return(unsigned int)-1073741675;
  v20 = 0i64;
  if( v19 )
    v20 = v8 + 1;
  v21 = qword_140D2C3B8 ? qword_140D2C3B8(v20, v19) : -1073741637;
  v22 = *(_DWORD *)(a2 + 32);
  if( *(_DWORD *)(a2 + 16) >= 0xFFFFFFD0 )
    return(unsigned int)-1073741675;
  v23 = *(_DWORD *)(a2 + 16) + 52;
  if( v23 < *(_DWORD *)(a2 + 16) + 48 )
    return(unsigned int)-1073741675;
  v7 = v23 + v22 < v23 ? 0xC0000095 : 0;
  if( v23 + v22 < v23 )
    return v7;
  *(_DWORD *)(a4 + 4) = 20;
  PoolWithTag = ExAllocatePoolWithTag(1ui64, 0x14ui64, 542329939i64);
  if( !PoolWithTag )
    return(unsigned int)-1073741801;
  *(_QWORD *)(a4 + 8) = PoolWithTag;
  *(_DWORD *)a4 = 0;
  v25 = v21 | 0x10000000;
  if( (VOID **)((char *)PoolWithTag + 4) < PoolWithTag )
    return(unsigned int)-1073741675;
  if( PoolWithTag + 1 > (VOID **)((char *)PoolWithTag + *(unsigned int *)(a4 + 4)) )
    return(unsigned int)-1073741789;
  *(_DWORD *)PoolWithTag = 4;
  *((_DWORD *)PoolWithTag + 1) = v25;
  v26 = ++*(_DWORD *)a4;
  v27 = *(_QWORD *)(a4 + 8);
  if( !v27 )
  {
    v28 = *(_DWORD *)(a4 + 4);
    v29 = -1;
    v30 = v28 + 12;
    if( v28 + 12 >= v28 )
      v29 = v28 + 12;
    v7 = v30 < v28 ? 0xC0000095 : 0;
    *(_DWORD *)(a4 + 4) = v29;
    if( v30 >= v28 )
    {
      v7 = 0;
      *(_DWORD *)a4 = v26 + 1;
    }
    return v7;
  }
  v31 = 0;
  for( k = *(_QWORD *)(a4 + 8); v31 < v26; k += v33 )
  {
    v33 = *(_DWORD *)k + 4;
    if( *(_DWORD *)k >= 0xFFFFFFFC || k + v33 < k )
      return(unsigned int)-1073741675;
    ++v31;
  }
  if( k + 4 < k )
    return(unsigned int)-1073741675;
  v7 = 0;
  if( k + 12 > v27 + (unsigned __int64)*(unsigned int *)(a4 + 4) )
    return(unsigned int)-1073741789;
  *(_DWORD *)k = 8;
  *(_QWORD *)(k + 4) = v4;
  ++*(_DWORD *)a4;
  return v7;
}

Referenced by:

sub_1405F50F8