RtlCreateRetpolineRelocationInformation

NTSTATUS __stdcall RtlCreateRetpolineRelocationInformation(
        UINT64 a1,
        UINT64 a2,
        INT64 a3,
        INT64 a4,
        INT64 a5,
        CHAR *result,
        UINT64 a7,
        INT64 a8,
        UINT64 a9){
  unsigned __int64 v11; 
  int v12; 
  unsigned __int64 v13; 
  size_t v14; 
  UINT16 *v15; 
  unsigned int v16; 
  unsigned __int8 v17; 
  _DWORD *v18; 
  unsigned __int64 v19; 
  _DWORD *v20; 
  unsigned __int64 v21; 
  _DWORD *v22; 
  unsigned __int64 v23; 
  unsigned int v24; 
  unsigned int v25; 
  unsigned int v26; 
  __int64 v28; 
  CHAR *v29; 
  char *v30; 
  CHAR *v31; 
  __int16 v32; 
  UINT16 *v33; 
  UINT16 *v34; 
  UINT16 *v35; 
  size_t v36; 
  __int64 v37; 
  __int64 v38; 
  NTSTATUS v39; 
  UINT16 *v40; 
  unsigned int v41; 
  unsigned int v42; 
  _DWORD *v43; 
  _DWORD *v44; 
  _DWORD *v45; 
  _DWORD *v46; 
  unsigned __int64 v47; 
  unsigned __int64 v48; 
  unsigned __int64 v49; 
  unsigned int v50; 
  __int64 v51; 

  v50 = a1;
  v11 = (unsigned __int64)(unsigned int)a1 >> 12;
  v12 = a1;
  v13 = 4 * ((unsigned int)a2 + 3 * v11);
  if( (unsigned int)a7 < v13 )
    return -1073741789;
  v14 = 8 * v11;
  if( (unsigned int)a9 < 8 * v11 )
    return -1073741789;
  memset(result, 0i64, v13);
  memset((VOID *)a8, 0i64, v14);
  v15 = 0i64;
  v16 = 0;
  v46 = 0i64;
  v17 = 0;
  v42 = 0;
  if( a3 )
  {
    v18 = (_DWORD *)(a3 + 12);
    v19 = a3 + 12 + *(unsigned int *)(a3 + 8);
  }
  else
  {
    v18 = 0i64;
    v19 = 0i64;
  }
  v47 = v19;
  if( a4 )
  {
    v20 = (_DWORD *)(a4 + 12);
    v21 = a4 + 12 + *(unsigned int *)(a4 + 8);
  }
  else
  {
    v20 = 0i64;
    v21 = 0i64;
  }
  v48 = v21;
  if( a5 )
  {
    v22 = (_DWORD *)(a5 + 12);
    v23 = a5 + 12 + *(unsigned int *)(a5 + 8);
  }
  else
  {
    v22 = 0i64;
    v23 = 0i64;
  }
  v49 = v23;
  v43 = v22;
  if( v12 )
  {
    do
    {
      if( (unsigned __int64)v18 < v19 && *v18 == v16 )
      {
        v28 = (unsigned int)v18[1];
        v44 = v18;
        v18 = (_DWORD *)((char *)v18 + v28);
        v24 = v28 - 8;
      }
      else
      {
        v44 = 0i64;
        v24 = 0;
      }
      LODWORD(a7) = v24;
      if( (unsigned __int64)v20 < v21 && *v20 == v16 )
      {
        v37 = (unsigned int)v20[1];
        v45 = v20;
        v20 = (_DWORD *)((char *)v20 + v37);
        v25 = v37 - 8;
      }
      else
      {
        v45 = 0i64;
        v25 = 0;
      }
      LODWORD(v51) = v25;
      if( (unsigned __int64)v22 < v23 && *v22 == v16 )
      {
        v38 = (unsigned int)v22[1];
        v46 = v22;
        v22 = (_DWORD *)((char *)v22 + v38);
        v43 = v22;
        v26 = v38 - 8;
      }
      else
      {
        v26 = 0;
      }
      v41 = v26;
      if( v17 || v24 || v25 || v26 )
      {
        v29 = result;
        *((_WORD *)result + 3) = v17;
        if( v17 )
        {
          v36 = RtlSizeOfRetpolineRelocationEntry(v17);
          memmove(v29 + 8, v15, v36);
        }
        v15 = (UINT16 *)(v29 + 12);
        v30 = v29 + 12;
        if( v24 )
        {
          RtlpCopyRetpolineRelocationBlockEntryArray(v15, 3u, (_WORD *)v44 + 4, v24, (__int64)&a7);
          LOWORD(v24) = a7;
          v30 += (unsigned int)a7;
        }
        if( v25 )
        {
          RtlpCopyRetpolineRelocationBlockEntryArray(v30, 4u, (_WORD *)v45 + 4, v25, (__int64)&v51);
          LOWORD(v25) = v51;
          v30 += (unsigned int)v51;
        }
        if( v26 )
        {
          RtlpCopyRetpolineRelocationBlockEntryArray(v30, 5u, (_WORD *)v46 + 4, v26, (__int64)&v41);
          LOWORD(v26) = v41;
          v30 += v41;
        }
        v31 = result;
        result = v30;
        *(_WORD *)v31 = v24;
        *((_WORD *)v31 + 1) = v25;
        *((_WORD *)v31 + 2) = v26;
        v32 = 4095;
        v33 = (UINT16 *)&v31[(unsigned __int16)v24 + 12 + (unsigned __int16)v25];
        v34 = (UINT16 *)&v31[(unsigned __int16)v24 + 12];
        v35 = (UINT16 *)((char *)v33 + (unsigned __int16)v26);
        while( v15 < v34 )
        {
          if( (*(_DWORD *)v15 & 0xFFFu) + 12 > 0x1000 )
          {
            v17 = 3;
            goto LABEL_39;
          }
          v15 += 2;
        }
        while( v34 < v33 )
        {
          v39 = RtlSizeOfRetpolineIndirectFixup(v34);
          if( (unsigned int)(unsigned __int16)(v32 & *v40) + v39 > 0x1000 )
          {
            v17 = 4;
            v15 = v40;
            goto LABEL_39;
          }
          v34 = v40 + 1;
        }
        while( 1 )
        {
          if( v33 >= v35 )
          {
            v17 = 0;
            v15 = 0i64;
            goto LABEL_39;
          }
          if( (unsigned int)(unsigned __int16)(v32 & *v33) + 6 > 0x1000 )
            break;
          ++v33;
        }
        v17 = 5;
        v15 = v33;
LABEL_39:
        v16 = v42;
        v19 = v47;
        v23 = v49;
        *(_QWORD *)(a8 + 8 * ((unsigned __int64)v42 >> 12)) = v31;
        v22 = v43;
        v21 = v48;
      }
      v16 += 4096;
      v42 = v16;
    }
    while( v16 < v50 );
  }
  return 0;
}

Referenced by:

MiCreateRetpolineRelocationInformation